Boxy.js、XHR、Ruby on Rails
我正在使用 Boxy.js 将我的 /signup 页面调用到模式窗口中。我猜是阿贾克斯。我希望页面在以这种方式调用时不使用布局呈现。
我尝试过:
layout proc {|controller| controller.request.xhr? ? false: "application" }
和:
def render(*args)
args.first[:layout] = false if request.xhr? and args.first[:layout].nil?
super
end
在应用程序控制器中,我用谷歌搜索的片段,但它们不起作用。 /signup 仍在制定布局。
以下是 Boxy 调用 /signup 时的部分标头:
请求 URL:http://localhost:3000/signup?_=1301708866195
请求方法:GET
X-Requested-With:XMLHttpRequest
I'm using Boxy.js to call my /signup page into a modal window. I suppose it's Ajax. I want the page to not render with layout when it's being called this way.
I tried:
layout proc {|controller| controller.request.xhr? ? false: "application" }
and:
def render(*args)
args.first[:layout] = false if request.xhr? and args.first[:layout].nil?
super
end
in application controller, snippets I googled but they don't work. /signup is still coming up with the layout.
Here's part of the headers when /signup is called by Boxy:
Request URL:http://localhost:3000/signup?_=1301708866195
Request Method:GET
X-Requested-With:XMLHttpRequest
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最佳实践是使用 Rails 的 js 响应,如下所示:
但由于 jQuery 默认情况下不会发送正确的 XHR 标头,因此您需要在 application.js 中添加如下内容:
如果您只想使用某些内容又快又脏,试试这个:
Best practice is to use Rails' js response, like so:
But because jQuery won't send the proper XHR headers by default, you'll need to add something like this to your application.js:
If you'd rather just use something quick and dirty, try this: