Changing devise default layouts

后端 未结 3 924
独厮守ぢ
独厮守ぢ 2021-02-05 10:17

I\'m trying to get devise to display a different layout template from the defaults for certain aspects.

I have this working when the user goes to the login page, but I n

相关标签:
3条回答
  • 2021-02-05 10:40

    If you name your alternate layout devise.html.erb, then the gem's controllers will naturally use it, without needing to be asked. Saves some code.

    0 讨论(0)
  • 2021-02-05 10:43

    You don't need to handle the layouts by your self, just do:

    rails generate devise:views
    

    Then, look at devise folder at views folder, you will see all the forms you need to customize

    0 讨论(0)
  • 2021-02-05 10:52

    Add this lines of code to your application.rb:

    config.to_prepare do
        Devise::SessionsController.layout "your_layout_name"
        Devise::RegistrationsController.layout "your_layout_name"
        Devise::ConfirmationsController.layout "your_layout_name"
        Devise::UnlocksController.layout "your_layout_name"
        Devise::PasswordsController.layout "your_layout_name"
    end
    

    If you want the same layout for all Devise views, except for when the user is editing its data, you could have something like this:

    config.to_prepare do
      Devise::SessionsController.layout "your_layout_name"
      Devise::RegistrationsController.layout proc{ |controller| user_signed_in? ? "application" : "your_layout_name" }
      Devise::ConfirmationsController.layout "your_layout_name"
      Devise::UnlocksController.layout "your_layout_name"            
      Devise::PasswordsController.layout "your_layout_name"        
    end
    

    For more information you can read this article

    0 讨论(0)
提交回复
热议问题