Is there a way to make a certain Rails view (e.g. index.html.haml
) use a certain template? This is done in a controller like so:
layout 'my_layout'
Is it possible to require a layout directly in a view? Thanks.
Is there a way to make a certain Rails view (e.g. index.html.haml
) use a certain template? This is done in a controller like so:
layout 'my_layout'
Is it possible to require a layout directly in a view? Thanks.
According to the Rails Guide, Layouts and Rendering
"When Rails renders a view as a response, it does so by combining the view with the current layout"
So it doesn't seem as if it's possible to change the layout once the view has begun to be rendered.
Moreover, I'd propose that determining the layout is more of a controller function. If you have logic in your view that tries to determine the layout, I'd bet that logic might better be placed in the controller.