Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails如何渲染局部_Ruby On Rails_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails Rails如何渲染局部

Ruby on rails Rails如何渲染局部,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我目前可以在JS中渲染部分,如下所示: $("#cmtList_<%= @commentable.id %>").prepend("<%=escape_javascript(render :partial =>"comments/comment", :locals => {:comment => @comment})%>"); $(“#cmtList”)prepend(“'comments/comment',:locals=>{:comment=>@c

我目前可以在JS中渲染部分,如下所示:

$("#cmtList_<%= @commentable.id %>").prepend("<%=escape_javascript(render :partial =>"comments/comment", :locals => {:comment => @comment})%>");
$(“#cmtList”)prepend(“'comments/comment',:locals=>{:comment=>@comment})%>”;
以上内容适用于呈现/返回一条新注释

现在我想重用相同的部分(保持干燥),但能够将注释数组作为@comments传递,并让Rails使用相同的部分循环遍历所有@comments记录(1个或更多),我尝试了这一点,但出现了以下错误:

$("#cmtList_<%= @commentable.id %>").prepend("<%=escape_javascript(render :partial => "comments/comment", :collection => {:comment => @comments})%>");
$(“#cmtList”)prepend(“'comments/comment”“,:collection=>{:comment=>@comments})%>”;
有什么想法吗

谢谢

试试:

$("#cmtList_<%= @commentable.id %>").prepend("<%=escape_javascript(render :partial => "comments/comment", :collection => @comments)%>");
$(“#cmtList”)prepend(“'comments/comment”“,:collection=>@comments)%>”;
它将查找局部变量“comment”

有关更多信息:

请尝试:

$("#cmtList_<%= @commentable.id %>").prepend("<%=escape_javascript(render :partial => "comments/comment", :collection => @comments)%>");
$(“#cmtList”)prepend(“'comments/comment”“,:collection=>@comments)%>”;
它将查找局部变量“comment”


有关更多信息:

请在escape\u javascript中尝试以下内容:

render :partial => "comments/comment", :collection => @comments
医生说这应该也行(对我来说太神奇了):

从此处选中“3.4.5渲染集合”:

在escape\u javascript中尝试以下内容:

render :partial => "comments/comment", :collection => @comments
医生说这应该也行(对我来说太神奇了):

从此处选中“3.4.5渲染集合”: