Rajat
Rajat

Reputation: 1388

How to add css to controller view on basis on controller name

I am new to ruby. I want to add css to controller view on basis of controller names. How can i do so because using all css is making difficult for me to change body color and other attributes using css.

Currently, my application.html.erb has :

<%= stylesheet_link_tag    "application", :media => "all" %>

to use all css files. How can i customize it to use particular css with particular controller.

Thanks in advance

Upvotes: 1

Views: 305

Answers (1)

Chris Heald
Chris Heald

Reputation: 62648

I use something like this in my ApplicationHelper.

def controller_stylesheet_link_tag
  return "" if params[:controller].blank?
  begin
    stylesheet_link_tag params[:controller].downcase, :media => "all"
  rescue Exception => e
    e.message
  end
end

Then, you just call <%=controller_stylesheet_link_tag %> in your layout.

Upvotes: 2

Related Questions