For a certain controller/action, I would like to serve only a specific subset of CSS assets. Is such a thing possible?
I want something like this in app/views/layouts/application.html.erb
<% if newsletter_show? %>
<%= stylesheet_link_tag "foo", "bar", "baz" %>
<% else %>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<% end %>
Note: when the condition is true, not only do I serve specific css files (foo, bar, and baz), I also purposely don’t serve javascript.
This works perfectly in development, but in production it fails because apparently we can’t have disjoint stylesheets, since they’re precompiled as a whole. Any way around this?
Option 1 :
If you add foo bar and baz to precompiles, it should work :
In config/application.rb :
Option 2 :
You could also create another css grouped file :
In app/assets/stylesheets/newsletter.css :
In config/application.rb :
In the view :
Don’t forget to recompile the assets 🙂