The best way to have separate stylesheets for different actions in Rails

I have one application layout that includes CSS stylesheets and wide CSSs, but do some controller actions need additional stylesheets that are used only for these s actions? What is the best way to enable them?

+3
source share
2 answers

If your application is usually something like:

<html>
  <head>
    <%= stylesheet_link_tag 'application' -%>
    <%= javascript_include_tag 'yui', 'application' -%>
  </head>
  <body>
    <%= yield -%>
  </body>
</html>

You can add other crop blocks, wherever you want, name whatever you want. I usually used this to include features specific to each page, wherever I wanted, even to the extent that perhaps partial deliveries deliver their own.

# layouts/application.html.erb
<html>
  <head>
    <%= stylesheet_link_tag 'application' -%>
    <%= javascript_include_tag 'yui', 'application' -%>
    <%= yield :head -%>
  </head>
  <body>
    <%= yield -%>
  </body>
</html>

# views/profiles/show.html.erb
<%= title("#{@user.name} Profile") -%>

<% content_for :head do -%>
  <%= javascript_include_tag 'gallery' %>
<% end %>

<%= render @user.photos %>

So, etc ...

+5
source

javascript - <% = yield: javascript% > ... . <% content_for: javascript do% > ... javascript ... <% end% >

, javascript html- erb .

Javascript, , .

0

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


All Articles