I have duplicate js.erb code between different model's ajax responses. I would like to refactor the duplicate js.erb code by passing arguments into a js.erb partial.
How do i render a js.erb partial from a js.erb file?
Just like you would render any other partial with erb. Let's say your partial is called _my_partial.js.erb
(note partials always start with _
), then in your main .js.erb
file you would do:
<%= render 'my_partial' %>
If your partial is in another directory, just use:
<%= render 'path/to/my_partial' %>
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