Here is my code
$(function(){
$('#new_post').bind('ajax:success', function() {
$('.posts').append("<%=escape_javascript(render :partial=>'post', :loca\
ls=>{:post=>Post.new})%>");
});
});
which results in a bizarre output, the page simply append <%=escape_javascript(render :partial=>'post', :locals=>{:post=>Post.new})%>
to my list.
Does anyone know how this could happen? Thanks!
I solved the problem eventually, thanks!
Actually I used that approach first, but it didn't work.
So it turns out I used
format.js { render :nothing => true }
in my controller, which will probably prevent javascript from rendering anything.
Besides, instead of using
<%= div_for post do %>
I used
<tr><td>
format for my single post and I guess that's part of reason why my javascript doesn't work
now my create.js.erb only renders
$('#posts').append("<%= escape_javascript(render(@post)) %>");
and it works.
Thank you guys, I am new to this community (also rails/javascript) but I have learned a lot already.
如果这是部分视图或视图,请确保以扩展名.js.erb
命名,否则可能无法正确进行ERB插值。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.