[英]Rails Controller respond_to return 404
I have a bunch of controllers in my rails app that return :html format. 我的Rails应用程序中有一堆返回:html格式的控制器。 When I try to access the url using .js extension it returns Completed 406 Not Acceptable.
当我尝试使用.js扩展名访问URL时,它返回Completed 406 Not Acceptable。 Shouldn't the correct behaviour is to return 404?
正确的行为不应该是返回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. 如果控制器的动作能够响应JS请求,但
action.js.erb
不存在,则会收到404
错误。 Since your controller only allows a response to HTML
, the 406 Not Acceptable
error would be expected behavior. 由于您的控制器仅允许对
HTML
进行响应,因此会出现406 Not Acceptable
错误。
If you want to handle JS requests, you'll have to have something like this: 如果要处理JS请求,则必须具有以下内容:
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. 调用该操作时,将加载相应的.js.erb或.html.erb文件。 More information is available on the Rails API
可在Rails API上获得更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.