Skip to content

Instantly share code, notes, and snippets.

@srih4ri
Created March 20, 2011 14:04
Show Gist options
  • Save srih4ri/878336 to your computer and use it in GitHub Desktop.
Save srih4ri/878336 to your computer and use it in GitHub Desktop.
Call it with <%= stylesheet_link_tag(*get_stylesheets) %> in your layouts file
def get_stylesheets
styles_path = "#{Rails.root}/public/stylesheets"
controller_name = controller.controller_path
action_name = controller.action_name
if File.exists? "#{styles_path}/#{controller_name}/#{action_name}.css"
"#{controller_name}/#{action_name}"
elsif ["create","edit","update"].include? action_name and File.exists? " #{styles_path}/#{controller_name}/new.css"
"#{controller_name}/new"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment