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:
Now that seemed pretty ceremonial to include in every controller so I added:
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?
Check Checkbox based on value in CSV
1:linq to sql joining two table
If i want all actions to use the same layout, i must just did this:.
class PostsController < ApplicationController def index @posts = Post.all render :layout => "application" end def show @post = Post.find(params[:id]) render :layout => "alternate" 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,.
class PostsController < ApplicationController layout "application" def index @posts = Post.all end def show @post = Post.find(params[:id]) end end