Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify layouts for certain controllers in ruby on rails

It's in my understanding that I 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.

like image 566
Yuval Karmi Avatar asked Nov 06 '22 16:11

Yuval Karmi


1 Answers

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.

like image 143
alex.zherdev Avatar answered Nov 15 '22 12:11

alex.zherdev