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

Answers


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.


Need Your Help

How to use Scala's singleton-object types?

scala types object singleton

I'm writing a class which serves as base class for a series of singleton objects. In each singleton objects, there will be vals representing certain properties, and I want to write a method which, ...

Iterating over files in Puppet (3.1)

ruby automation puppet

I am looking for a dry version of the following:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.