相关疑难解决方法(0)

在Rails 3中捕获自定义404的未知操作

我想在Rails 3中捕获未知的操作错误,该错误显示开发时的"未知操作"错误以及生产中的404.html.我尝试将此rescue_from处理程序放在我的ApplicationController上(以及实际的控制器,以防万一),但我仍然看到了丑陋的错误.

我在404上有自定义的东西,它不能是普通的.html文件.

我的路线:

match '/user/:id/:action', controller: 'users'
Run Code Online (Sandbox Code Playgroud)

我正在访问的URL: /user/elado/xxx

rescue_from代码:

rescue_from AbstractController::ActionNotFound, :with => :action_not_found

def action_not_found
  render text: "action_not_found"
end
Run Code Online (Sandbox Code Playgroud)

浏览器中的错误:

Unknown action

The action 'xxx' could not be found for UsersController
Run Code Online (Sandbox Code Playgroud)

在控制台中:

Started GET "/user/elado/xxx" for 127.0.0.1 at 2011-09-07 19:16:27 -0700

AbstractController::ActionNotFound (The action 'xxx' could not be found for UsersController):
Run Code Online (Sandbox Code Playgroud)

也试过rescue_from ActionController::UnknownAction.

有什么建议?谢谢!

ruby-on-rails http-status-code-404 ruby-on-rails-3

12
推荐指数
2
解决办法
1万
查看次数