6

How do I change layout in the devise controller?

Rails beginner
  • 14,321
  • 35
  • 137
  • 257

2 Answers2

9

You have to subclass the controller like in the following:

class SessionsController < Devise::SessionsController

  layout 'my_layout'  

end

And change the routes:

devise_for :users, :controllers => {:sessions => "sessions"}
lucapette
  • 20,564
  • 6
  • 65
  • 59
2

First, set your routes. For example:

devise_for :users, 
             :controllers => { 
                      :registrations => "users/registrations", 
                      :omniauth_callbacks => "users/omniauth_callbacks",
                      :sessions => "users/sessions"}

Second, create the file with the controller:

class Users::SessionsController < Devise::SessionsController  
  layout=>"my_layout"
end

Third, create the views for your controller in views/users/sessions. For instance, new.html.haml

=form_for user=User.new, :as=>"user", :url=>session_path("user") do |f|
  =f.label :email, 'email'
  =f.text_field :email
  =f.label :password, 'password'
  =f.password_field :password
  =link_to "Forgot your password?", new_password_path("user")
  .button_container{:style=>'border-top: none;'}
    =f.submit "sign in", :class=>'submit_button'

Hope this help.

Matteo Melani
  • 2,706
  • 2
  • 24
  • 30