How to write jQuery in Helper on Rails

How to write jQuery code inside a Helper function in Rails?

+3
source share
1 answer

If you have a lot of javascript code, I recommend using partial instead of putting it in lines in a helper method.

<!-- in views/layouts/application.html.erb -->
<% javascript_tag do %>
  <%= render :partial => 'layouts/do_something' %>
<% end %>

<!-- in views/layouts/_do_something.js.erb -->
function do_something() {
  // javascript code goes here
}

You can also add ERB tags in this partial.

Does this answer your question? Perhaps I did not understand this completely.

+6
source

Source: https://habr.com/ru/post/1714488/


All Articles