By default, layouts/application.html.haml
(.erb
if you are not using haml).
In fact, layout file could be set per controller or per action, instead of per view, per view folder.
There are few cases:
To change the default layout file for all controller (ie. use another.html.haml
instead of application.html.haml
)
class ApplicationController < ActionController::Base
layout "another"
# another way
layout :another_by_method
private
def another_by_method
if current_user.nil?
"normal_layout"
else
"member_layout"
end
end
end
To change all actions in a certain controller to use another layout file
class SessionsController < ActionController::Base
layout "sessions_layout"
# similar to the case in application controller, you could assign a method instead
end
To change an action to use other layout file
def my_action
if current_user.nil?
render :layout => "normal_layout"
else
render :action => "could_like_this", :layout => "member_layout"
end
end
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…