I currently am able to render a partial in JS like so:
$("#cmtList_<%= @commentable.id %>").prepend("<%=escape_javascript(render :partial =>"comments/comment", :locals => {:comment => @comment})%>");
The above works swell for rendering/returning one new comment.
Now I want to reuse that same partial(to stay DRY), but be able to pass an array of comments as @Comments, and have Rails loop through all the @comments records (1 or more) using the same partial, I tried this but it errors:
$("#cmtList_<%= @commentable.id %>").prepend("<%=escape_javascript(render :partial => "comments/comment", :collection => {:comment => @comments})%>");
Any ideas?
Thanks
Try:
which will look for a local variable “comment”.
For more info: http://guides.rubyonrails.org/layouts_and_rendering.html