0

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!

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

7 Comments

forgot, you need to use :partial
views/accounts/newbutton should be accounts/newbutton since accounts is the controller directory
I think this needs to be checked again
Still doesn't work. When rendering the same partial with an AJAX response it works. Could the problem be somewhere else?
I think you can place this .js.erb file under /views/accounts and call from your action view. this should help stackoverflow.com/questions/18437282/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.