In part, this is simply a “page fragment” (for example, a piece of cake ... but in the form of code). It is intended to fill a small part of the page; usually one that will be dynamically updated depending on the page variables.
It seems that you are confusing the purpose of layouts, views and partitions, in my opinion. If you want to dynamically load CSS / JS, put the " content_for " block in your profile views using the default:
Markup
#layouts/default.rb <html> <head> <title>Site Title</title> <%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" %> <%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js" %> <%= javascript_include_tag "application" %> <%= stylesheet_link_tag "main" %> <%= stylesheet_link_tag "reset" %> <%= yield :header_includes %> <%= csrf_meta_tag %> </head> <body> <%= yield %> </body> </html>
Views
#views/profiles/index.html.erb <% content_for :header_includes do %> <%= stylesheet "profile_custom_css" %> <% end %>
Partial
Particles can be used to store DRY code and output the output of certain header files, for example:
Partial
#views/elements/_custom_header.rb <% content_for :header_includes do %> <% headers.each do |type, value| %> <% if type == "java" %> <%= javascript_include_tag value %> <% else %> <%= stylesheet_link_tag value %> <% end %> <% end %> <% end %>
View
#views/profiles/index.html.erb <%= render :partial => 'elements/custom_header', locals: { :headers => [["java", "profile_custom"], ["stylsheeet", "profile_custom"]] } %>
Markup
#layouts/default.rb <html> <head> <title>Site Title</title> <%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" %> <%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js" %> <%= javascript_include_tag "application" %> <%= stylesheet_link_tag "main" %> <%= stylesheet_link_tag "reset" %> <%= yield :header_includes %> <%= csrf_meta_tag %> </head> <body> <%= yield %> </body> </html>
I have not tested passing partial locales as a hash, so the syntax may not be right, but this is what we would do to load the required code. An added benefit is that content_for only gives the content that was defined (IE you just have to include yield :custom_headers and it will only show if a content block is present)