Rails content_for overwrites rather than adds

I upload stylesheets and js files to <head> for performance reasons.

My site has several components, and each template wants to have its own additional header files inside <% yield(:head) .

I tested <% content_for :head do %> .. but then I understand that it is actually overwriting, not joining a specific section.

What are you guys using?

+6
source share
1 answer

content_for actually added by default. From the documentation if you need ...

 <% content_for :navigation do %> <li><%= link_to 'Home', :action => 'index' %></li> <% end %> <%# Add some other content, or use a different template: %> <% content_for :navigation do %> <li><%= link_to 'Login', :action => 'login' %></li> <% end %> 

If you used ...

 <ul><%= content_for :navigation %></ul> 

He infers ...

 <ul> <li><a href="/">Home</a></li> <li><a href="/login">Login</a></li> </ul> 

Just tested it locally in a rails 3.1.0 application to make sure this is still the case and it does it well.

+8
source

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


All Articles