Is there some sort of Master Page functionality in Ruby on Rails?
I've been a .Net developer for the past seven years or so, and been working with ASP.Net for the last couple of years. I'm now using Ruby on Rails for some projects, and I'm wanting to know if there is something in Ruby on Rails that lets you do master page type stuff?
Basically, I want a way to provide a consistent look and 开发者_StackOverflowfeel for the site with a header and footer and so on, and then just have each page put its content inside of that. How do you accomplish this?
in your rails project in app/layouts/application.(html.erb|html.haml), this is the layout or equivalent for master. You can also create other layouts and specify the layout to use for each action :
render :index, :layout => "awesome"
Or specify the layout for a whole controller :
class PostController < ActionController::Base
layout "super_awesome"
end
You can use layout which is look like master page in ASP.Net, there are many way to assign master page to your rail application :
- For single page :
class EmployeesController < ApplicationController layout "submaster" # --- end
submaster is located at app/views/layouts/submaster.html.erb
- For whole application :
class ApplicationController < ActionController::Base layout "main" #... end
main is located at app/views/layouts/main.html.erb
- Layout at run-time :
class EmployeesController < ApplicationController layout :emp_layout def show # --- end private def emp_layout @current_user.admin? ? "admin" : "submaster" end end
If current user is a admin user, they'll get a admin layout else submaster layout.
If possible, please check yield identifies in rails.
精彩评论