2

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?

Chuck Norris
  • 15,207
  • 15
  • 92
  • 123
com
  • 2,606
  • 6
  • 29
  • 44

1 Answers1

4

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"
Community
  • 1
  • 1
Gazler
  • 83,029
  • 18
  • 279
  • 245