In my controller I'm using layout 'application', :only => :edit
But I noticed that layout 'application', :for => :edit works as well.
Just curious because docs only mention :only & :except. I can't explicitly find :for in any docs for the layout method.
Rails v2.3 - layout (railsapi.com)
Rails v3.1 - layout (apidock.com)
As I commented above, Rails is ignoring your :for parameter and should just be using the 'application' layout for all actions.
As far as rendering multiple layouts, it seems you can only have a single layout ... line for your controller; if you have multiples, it will only use the last one. And if the last one has an :only or :except parameter, it should fall back to the application layout for all the other actions. If it's not properly using the application layout and rendering without any layout whatsoever, make sure the previous developer didn't put something like layout nil somewhere in your controller/application.
If you want to handle multiple layouts inside your controller, you could also try this:
class UsersController < ApplicationController
layout :choose_layout
def choose_layout
if action_name == "edit"
"application"
else
"login"
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With