I have a bunch of controllers in my rails app that return :html format. When I try to access the url using .js extension it returns Completed 406 Not Acceptable. Shouldn't the correct behaviour is to return 404?
Thanks
You would get a 404
error if your controller's action was able to respond to the JS request but the action.js.erb
did not exist. Since your controller only allows a response to HTML
, the 406 Not Acceptable
error would be expected behavior.
If you want to handle JS requests, you'll have to have something like this:
respond_to do |format|
format.js
format.html
end
This will load the corresponding .js.erb or .html.erb files when that action is called. More information is available on the Rails API
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.