[英]How to you render JS.ERB files that is in another controller?
i do not quite understand what is wrong with my code - it is even causing my server to hang up. 我不太了解我的代码有什么问题-甚至导致服务器挂断。
What i need to do is for the controller to return a JS script that when executed, will append a rendered partial to my $(".reviews") 我需要为控制器返回一个JS脚本,该脚本在执行时会将渲染的部分追加到我的$(“。reviews”)
# test.html.erb
$.getScript("/test");
# controller
wants.js do
render :partial => "/shared/activity"
end
#/shared/activity.js.erb
$("#reviews").append("<%= escape_javascript(render(:partial => /shared/activity )) %>");
I suspect there is something wrong with the way i am asking for the render in my controller. 我怀疑我在控制器中请求渲染的方式有问题。 In fact, it throws up all sorts of weird errors. 实际上,它引发了各种奇怪的错误。
Since you have both activity.js.erb
and activity.html.erb
, it will probably help if you specify which one you want to render: 由于您同时具有activity.js.erb
和activity.html.erb
,如果您指定要渲染的对象,则可能会有所帮助:
# test.html.erb
$.getScript("/test");
# controller
wants.js do
render :partial => "/shared/activity.js.erb"
end
#/shared/activity.js.erb
$("#reviews").append("<%= escape_javascript(render(:partial => '/shared/activity.html.erb' )) %>");
You call yourself in your partial. 你称自己为局部。 So you have an infinite loop. 所以你有一个无限循环。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.