Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Jquery rendering js.erb partial from another js.erb file

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?

like image 700
GTDev Avatar asked Feb 05 '13 06:02

GTDev


1 Answers

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' %>
like image 72
mockaroodev Avatar answered Nov 15 '22 21:11

mockaroodev