仅当 .js 格式时才在控制器中查询(如果是 .html 则不查询)
采用标准控制器操作重定向代码:
respond_to do |format|
format.html { redirect_to companies_url }
format.js
end
如果格式为 .js,是否有办法仅执行几个附加查询?
Take the standard controller action redirect code:
respond_to do |format|
format.html { redirect_to companies_url }
format.js
end
Is there a way to only perform a couple of additional queries if the format is .js?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然,只需将它们添加到
format.js
响应程序块中Sure, just add them in the
format.js
responder block如果您只想处理操作中的 .js 格式,您可以像这样指定
respond_to :js
:..并且此操作将仅响应 .js 格式。或者您可以在操作中使用
request.xhr?
来验证传入格式。if you want to handle only .js format from action you can specify
respond_to :js
like this:..and this action will respond only to .js format. Or you can use
request.xhr?
in your action to verify incoming format.