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

Jackson Cunningham picture Jackson Cunningham · May 4, 2015 · Viewed 8k times · Source

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.

Answer

Bernie Chiu picture Bernie Chiu · May 4, 2015

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