When someone goes to my site with wrong route, rails responses with 404
code and the error
ActionController::RoutingError No route matches
Can I response with 410
code on the rails's error instead of 404
?
When someone goes to my site with wrong route, rails responses with 404
code and the error
ActionController::RoutingError No route matches
Can I response with 410
code on the rails's error instead of 404
?
I am not sure why you would want to as a 410 error (Gone) is for a resource that was once available but isn't anymore.
If you follow the answer at https://stackoverflow.com/a/5360684/219743 then it allows you to do it.
Just change the render_404 method to
def render_404
if /(jpe?g|png|gif)/i === request.path
render :text => "404 Not Found", :status => 410 # Change the status here
else
render :template => "shared/404", :layout => 'application', :status => 410 #and here
end
end
If you still want to point to 404.html in the public folder:
render :file => "#{Rails.root}/public/404.html"