Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass the user_id on escape javascript while render on jquery

How can I pass the user_id on escape javascript while render on jquery?

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>
like image 877
chandramouli Avatar asked Nov 05 '22 10:11

chandramouli


1 Answers

You could pass your partial to javascript as:

$("#user tr:last").after("<%= escape_javascript(render :partial => 'user_item', :locals => {:user_item => User.find(@user_id)}) %>")

Where @user_id would be the user you wanted to load. This would render the partial on page load though, so each click of #addPerson would load the same partial with the same @user_id.

If that's not your intention you could try using a multiple record form or create a new partial with javascript or an ajax call to your server.

like image 57
Pan Thomakos Avatar answered Nov 11 '22 04:11

Pan Thomakos