2

Rails 4 by default will require the entire tree of css and javascripts for every view which I do not want. I just want to be able have the application.css and the individual controllers css stylesheet for each view.

To do this I have removed *= require_tree . in the application.css and added config.assets.precompile << "*.css" in the config/environments/development.rb which from another question on here should auto load all css files. I have added <%= stylesheet_link_tag params["clients"] %> and also tried <%= stylesheet_link_tag params[:clients] %> in the view but I cannot get the controller specific style to show up. In the page source it looks like <link href="" media="screen" rel="stylesheet" />

In my opinion I think the behaviour I am looking for should be default and by the description in the rails guides makes it sound like it is. If anyone could help me out that would be great. Thanks!

Brent Moses
  • 243
  • 5
  • 14

1 Answers1

2

I'm not sure what the params['clients'] part is about, do you mean params[:controller] (which would be better accomplished through controller.controller_name I think)? It should just be <%= stylesheet_link_tag 'name_of_stylesheet' %> that you want.

Graham Conzett
  • 8,344
  • 11
  • 55
  • 94
  • Thanks. This was a dumb mistake on my part. I did mean params[:controller] and I mistook it for meaning params[:your_controller_name_here] from http://stackoverflow.com/questions/16386545/controller-specific-stylesheets-in-rails-3-inheritence. Though your solution works great. Thanks again. – Brent Moses Nov 01 '13 at 12:54