I have a 'project' form as a partial. I'm trying to use jquery to render the partial when user clicks a button:
$('.projects').append("<%= render partial: 'projects/project') %>").html_safe
But using the above code is literally rendering "<%= render partial: 'projects/project') %>" on the page instead of the actual partial.
I believe renaming your file extension from xxx.js
to xxx.js.erb
might solve your problem.
Try this:
$('#projects').html('<%= escape_javascript render 'projects/project' %>');
Note: As Bernie Chiu
suggested you need to change file extension from xxx.js
to xxx.js.erb
Try:
$('.projects').append("<%= j render partial: 'projects/project') %>");
j
is the alias for escape_javascript
.
See documentation for escape_javascript helper.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With