Another way to apply a custom layout for an action is as follows.
According to How to Create Custom Layouts , you can also set the layout for specific Devise controllers using the callback in config / environment.rb (rails 2) or config / application.rb (rails 3). This needs to be done in the to_prepare callback. because it is executed once during the production process and before each request in development. "
config.to_prepare do Devise::SessionsController.layout "devise" Devise::RegistrationsController.layout proc{ |controller| user_signed_in? ? "application" : "devise" } Devise::ConfirmationsController.layout "devise" Devise::UnlocksController.layout "devise" Devise::PasswordsController.layout "devise" end
Typically, the distinction between layouts is made between pages behind inputs and pages that do not require authentication, so this approach works most of the time. But I also experimented using the action_name to set the layout for a specific action, and it worked like a charm:
config.to_prepare do Devise::SessionsController.layout proc{ |controller| action_name == 'new' ? "devise" : "application" } end
I think this is better and built into the way to change the layout based on the development of the controller / action, instead of creating an assistant in the ApplicationController.
Zeeshan Aug 21 '11 at 17:08 2011-08-21 17:08
source share