DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Autoinclude CSS Files By Controller/Action Name

07.26.2005
| 10310 views |
  • submit to reddit
        
def stylesheet_auto_link_tags
  stylesheets_path = "#{RAILS_ROOT}/public/stylesheets/"
 
  candidates = [ "#{controller.controller_name}", 
                 "#{controller.controller_name}_#{controller.action_name}" ]
 
  candidates.inject("") do |buf, css| 
    buf << stylesheet_link_tag(css) if FileTest.exist?("#{stylesheets_path}/#{css}.css")
    buf
  end
end

Compliments of Dema

Note: Anyone interested in this might also be interested in the bundled_resource plugin (google for it).    

Comments

Snippets Manager replied on Mon, 2012/05/07 - 2:13pm

Good show! I had something like this awhile back, but it didn't quite work and I abandoned it in some alley.

Snippets Manager replied on Mon, 2012/05/07 - 2:13pm

Hey, you stole my code!!! ;) Hehe, thanks Duane, I'll begin posting my snippets here as well.