1

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.