我有一个before_filter
在我的 Rails 应用程序中,将用户发送到login_url
如果他们在提交请求(以 html 或 js 格式)时注销。
我想要我的format.js
产生相同的结果format.html
,在以下情况下使用“通知”布局渲染视图。我怎样才能做到这一点?
respond_to do |format|
format.js
format.html{ render :layout => "notice" }
end
您可以强制使用这样的可用格式:
respond_to do |format|
format.js { render :layout => "notice", :formats => [:html] }
format.html { render :layout => "notice" }
end
EDIT:
您需要的是文档的某些部分被响应替换。这是通过使用执行此操作的 javascript 进行响应来完成的:
在你的控制器中:
respond_to do |format|
format.js
format.html { render :layout => "notice" }
end
在你的login.js视图中:
$('#whatever').html('<%= escape_javascript( render :login, formats: [ :html ]) %>')
...或类似的东西
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)