Specify layouts for specific controllers in ruby ​​on rails

In my understanding, I can specify the layout for the controller by setting

layout 'mylayout'

in the controller file. I also understand that I can specify certain actions for which the layout will be called using :onlyand :exceptas such: layout 'mylayout' ,: only => [: index ,: new] or layout 'mylayout' ,: except => [: index ,: new]

What interests me is, can I put layout 'mylayout'applications in my controller and specify what will be displayed only for certain controllers with something like :only_controllerand :except_controller, or do I need to specify layout 'mylayout'in each controller I want it to be displayed?

The reason for this is that I have several controllers that are responsible for the admin section of my site, and I would like to have a different layout for them.

+5
source share
1 answer

Inherit admin controllers from AdminControllerand create the layout admin.html.erb. Thus, all controllers for your admin section will have this layout.

+2
source

All Articles