Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different layout for devise controller, problem when form errors

i assigned a different layout for my sign in and sign up view in the application_controller like this:

  layout :layout_by_resource

  def layout_by_resource
    if devise_controller? && resource_name == :user && action_name == 'new'
      "login"
    else
      "application"
    end
  end

when entering sign in or sign up information it works perfectly. but there are validation-errors on sign up, the standard application layout gets rendered. any advice what i have done wrong?

thanks!

like image 304
trnc Avatar asked Apr 19 '11 09:04

trnc


2 Answers

  def layout_by_resource
    devise_controller? ? 'login' : 'application'
  end

;)

like image 75
Diego Plentz Avatar answered Oct 07 '22 14:10

Diego Plentz


okay, fixed it myself ;) had to check for the create action...

  layout :layout_by_resource

  protected

  def layout_by_resource
    if controller_name == 'registrations' && action_name == 'new'
      'login'
    elsif controller_name == 'registrations' && action_name == 'create'
      'login'
    elsif controller_name == 'sessions' && action_name == 'new'
      'login'
    else
      'application'
    end
  end
like image 4
trnc Avatar answered Oct 07 '22 14:10

trnc