想给项目加个 404 处理,看了下 RubyChina 的代码: application_controller.rb
def render_404
render_optional_error_file(404)
end
def render_403
render_optional_error_file(403)
end
def render_optional_error_file(status_code)
status = status_code.to_s
if ["404","403", "422", "500"].include?(status)
render :template => "/errors/#{status}", :format => [:html], :handler => [:erb], :status => status, :layout => "application"
else
render :template => "/errors/unknown", :format => [:html], :handler => [:erb], :status => status, :layout => "application"
end
end
加上了似乎也不起作用,错误 url 根本就没进 application_controller.rb 似乎跟 routes.rb 有关系,似乎又跟 require 'api'有关系,求指教~ 我用的是 rails3.0