Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9156959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:53:45+00:00 2026-06-17T12:53:45+00:00

In the default layout of application.html.erb that gets generated the book has added this

  • 0

In the default layout of application.html.erb that gets generated the book has added this line of code, saying because rails loads all of the stylesheets at once, we need a convention to limit controller-specific rules to pages associated with that controller. Using the controller_name as a class name is an easy way to do that..and they have added this code:

<body class = '<%= controller.controller_name %>' >

But still I don’t understand what is it doing? Can someone explain it ? and actually is it a common and recommended thing to do or not?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:53:47+00:00Added an answer on June 17, 2026 at 12:53 pm

    It’s a way to scope your css based on the controller.

    Let’s say you have 2 models: Car and Brand, and you want the top menu to be green on the page where you display all the cars, and red on the page where you display the brands.

    On the page where you list all the cars (cars#index), the body would look like that:

    <body class="cars">
    

    On the page where you list all the brands (brands#index), the body would look like that:

    <body class="brands">
    

    So you would be able to write your css like the following:

    .cars .menu {
        background: green;
    }
    
    .brands .menu {
        background: red;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code snippet in an email layout: <div> <?php echo $this->Html->image('Layouts/default/Logo.png', array(
So, I have the following line of code in my <head> , inside app/views/layouts/application.html.erb
I have a rails application using views/layouts/application.html.erb as the default site template. I'm just
I have an application layout in my rails app to give a default header/footer
this is my pom.xml <repositories> <repository> <url>http://download.java.net/maven/2/</url> <id>hibernate-support</id> <layout>default</layout> <name>Repository for library Library[hibernate-support]</name> </repository>
I just reformatted the default layout of my CakePHP application. I eliminated as much
I have a MVC3 application, based on default layout from VS 2010, which I
http://0.0.0.0:3000/ Sprockets::FileNotFound in Home#index Showing /home/user1/rorblog/app/views/layouts/application.html.erb where line #6 raised: couldn't find file 'jquery'
I am starting an application that will use HTML / CSS. While I'm fairly
I have added this to my config/application.rb file: config.action_view.javascript_expansions[:defaults] = %w(jquery rails application) and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.