开发者

Specify layouts for certain controllers in ruby on rails

It's in my understanding that I 开发者_JS百科can specify a layout for a controller by putting

layout 'mylayout'

in the controller file. I further understand that I can specify certain actions that the layout will be invoked for with :only and :except as such: layout 'mylayout', :only => [:index, :new] or layout 'mylayout', :except => [:index, :new]

What I am wondering is, can I put layout 'mylayout' in my application controller and specify that to be rendered for only certain controllers with something like :only_controller and :except_controller, or do I have to specify layout 'mylayout' in every controller I want it to be rendered in?

The reason for this is that I have a few controllers that are in charge of the admin section of my site, and I'd like to have a different layout for them.


Have the admin controllers inherit from an AdminController and create an admin.html.erb layout. That way all the controllers for your admin section will have this layout.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜