render :partial generates only one time on escape_javascript
render :partial generates only one time on escape_javascript
eg
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$("#addPerson").click(function(){
$("#user tr:last ").after("<%= escape_javascript(render :partial => 'user_item', :locals =>{:user_item => User.new}) %>");
return false;
});
});
</script>
and I have checked object_id in the user_item partial file it is showing same object_id until saving and saves only last item.
<%= user_item.object_id %>
wh开发者_Go百科ich results
12354
every time. Please help me to solve this problem.
it's because the partial is render only once time.
The HTML file is generate only one time. When you call this Javascript function, it don't call the partial because it's already generate.
If you want a new generation each time. You need made a server call with your user_id and get the HTML in return.
精彩评论