Rails tip: Automatically link a controller’s stylesheet
This is a simple application helper I wrote to reduce the tediousness of linking stylesheets for each controller. It will link the controller’s stylesheet (located at public/stylesheets/[controller_name].css) if it exists but it won’t complain if it doesn’t. I use it in pretty much every Rails project to keep things organized. It’s super simple to set up.
Simply add this to your application helper (located at app/helpers/application_helper.rb):
def controller_stylesheet_link_tag
stylesheet = "#{params[:controller]}.css"
if File.exists?(File.join(Rails.public_path, 'stylesheets', stylesheet))
stylesheet_link_tag stylesheet
end
end
…and put this in your application layout (located at app/views/layouts/application.html.erb):
<%= controller_stylesheet_link_tag %>
Notes
-
stabilefeasi liked this
-
priorfaint23 liked this
-
operacancell liked this
-
operosephilo liked this
-
uprighttatty liked this
-
unenlightenm liked this
-
partiescutelesbian liked this
-
-buy-viagra-online-uk- reblogged this from shaunchapman
-
recumbentreg liked this
-
fictitiousse liked this
-
a1125freephotoeditornews liked this
-
download-audio-books-cheap reblogged this from shaunchapman
-
tester-webmaster liked this
-
vasilii-petrovich liked this
-
gliermo liked this
-
bubaleh liked this
-
morethanaprogrammer reblogged this from shaunchapman
-
lucashungaro reblogged this from rubyquicktips
-
sanemat reblogged this from rubyquicktips
-
atm09td reblogged this from rubyquicktips
-
jpunt reblogged this from rubyquicktips
-
rubyquicktips reblogged this from shaunchapman and added:
that shaunchapman...It is a nice way...organized and it’s
-
shaunchapman posted this
