Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Autoinclude CSS Files By Controller/Action Name

DZone's Guide to

Autoinclude CSS Files By Controller/Action Name

· ·
Free Resource

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).
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}