Reputation: 4783
I'm trying to use a non-controller-connected button to insert a rails partial in a div. As I'm not doing this via the controller, I can't use the standard format.js to do this. The script is placed inside the assets/javascripts
folder and this is the important code inside of it:
accounts.js.erb:
$("#account-div").append("<%= j render("newbutton") %>");
When I'm trying to open the site, I get the following error:
undefined method `render' for #<#<Class:0x007fbc7bd060f8>:0x007fbc7aaa0e40>
The code above works when its placed inside the AJAX response via the respond.to block. How can I pass the correct path so that the render method finds the _newbutton.html.erb
file, which resides inside the views/accounts/
folder? Thanks!
Upvotes: 0
Views: 256
Reputation: 22926
Since assets cannot use render method, move your .js.erb files into views directory and use
<%= j render(:partial => 'accounts/newbutton') %>
Reference - Rendering partial in js.erb file and https://stackoverflow.com/a/6309970/184184
Upvotes: 1