Dynamic error pages in Rails 3

前端 未结 4 2104
抹茶落季
抹茶落季 2020-12-02 08:34

In Rails 2.3.x, you can override render_optional_error_file like so:

# ApplicationController.rb
protected
  def render_optional_error_file(statu         


        
4条回答
  •  醉话见心
    2020-12-02 09:22

    In rails 3.2, it's easier than that:

    Add this to config/application.rb:

    config.exceptions_app = self.routes
    

    That causes errors to be routed via the router. Then you just add to config/routes.rb:

    match "/404", :to => "errors#not_found"
    

    I got this info from item #3 on the blog post "My five favorite hidden features in Rails 3.2" by By José Valim.

提交回复
热议问题