Never been to DZone Snippets before?

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

Autoinclude CSS Files by Controller/Action Name (See related posts)

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 on this post

dema posts on Jul 25, 2005 at 21:19
Hey, you stole my code!!! ;)

Hehe, thanks Duane, I'll begin posting my snippets here as well.
technoweenie posts on Jul 25, 2005 at 22:37
Good show! I had something like this awhile back, but it didn't quite work and I abandoned it in some alley.

You need to create an account or log in to post comments to this site.


Click here to browse all 4861 code snippets

Related Posts