I am trying to render a partial inside my js file and append it to my html on a javascript event (click). I tried to follow this and use the escape_javascript method : Rendering partial in js.erb file but unfortunately it doesnt work. This is my js file :
$(document).ready(function(){
$("#add_resident").click(function(){
$(".resident").append('<%= escape_javascript(render partial: "resident_form") %>');
})
})
this is my partial :
<%= label_tag "first name" %>
<%= text_field_tag "resident[:first_name]" %>
<%= label_tag "last name"%>
<%= text_field_tag "resident[last_name]" %>
<%= label_tag "birthdate"%>
<%= text_field_tag "resident[birthdate]" %>
the javascript is indeed triggered on the .click event but it is rendering <%= escape_javascript(render partial: "resident_form") %> as a string. What is the correct way to fix that.