Tag: http response codes

如何在使用rescue_from时使用Rails4和RSpec测试渲染状态:404

我有一个带有’PagesController’的Rails4应用程序。 当找不到页面时,show-method抛出一个自定义的exception’PageNotFoundError’。 在控制器的顶部,我rescue_from PageNotFoundError, with: :render_not_found定义了rescue_from PageNotFoundError, with: :render_not_found render not found是PagesController的私有方法, PagesController所示: def render_not_found flash[:alert]=t(:page_does_not_exists, title: params[:id]) @pages = Page.all render :index, status: :not_found #404 end rails-log in development-mode显示: Started GET “/pages/readmef” for 127.0.0.1 at 2013-08-02 23:11:35 +0200 Processing by PagesController#show as HTML Parameters: {“id”=>”readmef”} .. Completed 404 Not Found in 14ms (Views: 12.0ms) […]