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 900175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:20:26+00:00 2026-05-15T15:20:26+00:00

Asp.net WebForms and MVC has a concept of Masterpages which make it easy to

  • 0

Asp.net WebForms and MVC has a concept of Masterpages which make it easy to define a one time layout for all the page of your site. In Rails I’m struggling to find an equivalent usage pattern or feature.

From what I’ve read it’s really easy to define a layout in every action with:

layout: 'viewname'

Now that seemed pretty ceremonial to include in every controller so I added:

layout: 'application'

in the base ApplicationController.

So far this is working ok unless I have a more specific layout in the view pages. Is this common technique for getting a consistent style in your Rails application?

  • 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-05-15T15:20:27+00:00Added an answer on May 15, 2026 at 3:20 pm

    Imagine a simplified blog where we have a controller called PostsController which has two actions: index and show

    The index action is called when the user hits http://yourwebsite.com/posts – this action displays all of the available blog posts.

    The show action is called when a user gets a specific blog article – i.e. http://yourwebsite.com/posts/article-about-something-interesting

    Let’s say that we want the index page to have a two column layout and we want the show page for each blog-article to have a three column layout. To achieve this, we would simply define two separate layouts (in app/views/layouts folder) – we’ll call the two column layout “application” and we’ll call the three-column layout “alternate”.

    In order to get the index page to use the two-column layout and the show page to use the three-column layout, we could just do the following in our controller:

    class PostsController < ApplicationController
      def index
        @posts = Post.all
        render :layout => "application"
      end
    
      def show
        @post = Post.find(params[:id])
        render :layout => "alternate"
      end
    end
    

    If we want all actions to use the same layout, we can just do this:

    class PostsController < ApplicationController
      layout "application"
    
      def index
        @posts = Post.all
      end
    
      def show
        @post = Post.find(params[:id])
      end
    end
    

    Finally, if we do not specify which layout we want to use, then Rails will by default, render any layout which has the same name as the resource we are displaying. So in our example, where our resources are called “Posts”, if we define a third layout called posts.html.erb (in app/views/layouts) then Rails will automatically use that layout when the user renders any of the actions in the PostsController – providing of course that we have not explicitly asked Rails to render another layout….

    Hope it helps,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Although ASP.NET MVC seems to have all the hype these days, WebForms are still
I am adding ASP.NET MVC to an existing WebForms application. For the time being,
Microsoft has really been pushing ASP.NET MVC, and one of its major strengths over
I have a hybrid ASP.NET WebForms/MVC project. In my Master Page, I have a
I have developed a webapplication in both ASP.NET MVC and ASP.NET Webforms and i'm
I know the difference between ASP.NET webforms and ASP.NET MVC and I've seen quite
Some site I'm programming is using both ASP.NET MVC and WebForms. I have a
I'm just wondering, if I have an ASP.net Web Application, either WebForms or MVC,
Does ASP.NET MVC provide any way to implement UpdateProgress WebForms control analog? Can anyone
I asked this question: Is ASP.NET MVC destined to replace Webforms? and a few

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.