Asp.net MasterPage equivalent in Ruby on Rails, Trying to define a site wide layout


Asp.net MasterPage equivalent in Ruby on Rails, Trying to define a site wide layout



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?


Which strategy to choose for building web based business application

1:

ASP.NET MVC output cache with dynamic fragment
Imagine a simplified blog where i have a controller called PostsController which has two actions: index and show. Redirect site from www.a.com to a.com in asp.net mvc The index action is called when the user hits http://yourwebsite.com/posts - this action displays all of the available blog posts.. Jquery thickbox to work with Url.Action link in Asp.net mvc The show action is called when a user receive s a specific blog article - i.e. Structuring several mostly-static pages in ASP.NET MVChttp://yourwebsite.com/posts/article-about-any thing-interesting. Function to display a DateTime string or an empty string Let's say this i want the index page to have a two column layout and i want the show page for each blog-article to have a three column layout. Visual Studio 2010 RC + ASP.NET MVC 2 RTM won't re-target from .NET Framework 4 to 3.5 To achieve this, i 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".. MVC2 and Session Start Event In rule to receive the index page to use the two-column layout and the show page to use the three-column layout, i could just did 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 i want all actions to use the same layout, i must just did this:.
class PostsController < ApplicationController   layout "application"    def index     @posts = Post.all   end    def show     @post = Post.find(params[:id])   end end 
Finally, if i did not specify which layout i want to use, then Rails will by default, render any layout which has the same name as the resource i are displaying. So in our example, where our resources are called "Posts", if i define a third layout called posts.html.erb (in app/views/layouts) then Rails will automatically use this layout when the user renders any of the actions in the PostsController - providing of course this i have not explicitly asked Rails to render ananother layout..... Hope it helps,.

2:

This PDF book excerpt from Rails for .Net Developers has a pretty good explanation of Rails layouts, along with a comparison to ASP.Net MasterPages. Since it seems to job pretty well, it's probably used fairly often, at least by developers familiar with the master page concept..


98 out of 100 based on 43 user ratings 558 reviews

@