Search code examples
javascriptjqueryruby-on-railsrubypartial

Ruby on Rails: How to Render Partial in a view via Jquery


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.


Solution

  • I believe renaming your file extension from xxx.js to xxx.js.erb might solve your problem.