How do I change layout in the devise controller?
Asked
Active
Viewed 4,269 times
2 Answers
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
-
Then I get this error: Template is missing Missing template sessions/new with. I have changed the devise view folder to sessions – Rails beginner Feb 11 '12 at 23:59
-
You have to change the `devise/sessions` folder to `sessions'. – lucapette Feb 12 '12 at 10:19
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