Domanda

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?

È stato utile?

Soluzione

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' %>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top