Different layout for controller development, problem with form errors

I assigned a different layout for my login and registration in the application_controller application as follows:

  layout :layout_by_resource

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

When you log into the system or register information, it works great. but there are validation errors during registration, a standard application layout is created. Any advice what I did wrong?

thank!

+5
source share
2 answers
  def layout_by_resource
    devise_controller? ? 'login' : 'application'
  end

;)

+7
source

OK, I fixed it myself;) I had to check 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
+4
source

All Articles