davidb
davidb

Reputation: 8954

Why does rails app return 406 instead of 404 in some cases?

I have a huge Rails app that is running quit well but I have a problem with google because of some nasty behavior of the app. When I call

http://railsapp.com/index.html

Which doesnt exist the app returns an 404 error which is correct. But when I call

http://railsapp.com/index.htm

It returns an 406 error wich isnt that great. This problem appears every time a non existing file with .htm extension is requested. How can I make my rails app return 404 instead of 406?

Upvotes: 2

Views: 303

Answers (2)

Dipak Panchal
Dipak Panchal

Reputation: 6036

406.htm file is not available in your public folder so that you get error -non existing file. Add 406.html file in your public folder as per your layout and then try.

Upvotes: 1

Dipak Panchal
Dipak Panchal

Reputation: 6036

try this

 respond_to do |format|    
   format.html {}
   format.js {}        
  end

because in your "#{RAILS_ROOT}/public/.." 406.htm file is not their so that it gives error and 404.html file is available in public folder so that it's call.

in your {RAILS_ROOT}/public these are the file is their

1. 404.html
2. 422.html
3. 500.html

if you use these file then it call else it will give error like file does not exist.

or

you can also do this In the ApplicationController define a method like:

def render_404
  render :file => "#{RAILS_ROOT}/public/404.html",  :status => 404
end

Upvotes: 1

Related Questions