Devise not obeying :path_names setting for sign_in route - ruby-on-rails

I'm trying to setup Devise 3.1.0 with Rails 4.0.0.
I have configured my router like so:
devise_for :users,
:controllers => {
:registrations => 'users/registrations',
:sessions => 'users/sessions'
},
:path_names => {
:sign_in => 'login',
:sign_out => 'logout',
:sign_up => 'new'
}
new_user_session GET /users/login(.:format) users/sessions#new
user_session POST /users/login(.:format) users/sessions#create
destroy_user_session DELETE /users/logout(.:format) users/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
user_registration POST /users(.:format) users/registrations#create
new_user_registration GET /users/new(.:format) users/registrations#new
edit_user_registration GET /users/edit(.:format) users/registrations#edit
PATCH /users(.:format) users/registrations#update
PUT /users(.:format) users/registrations#update
DELETE /users(.:format) users/registrations#destroy
I've also turned on scoped views, and overridden the default views and registration controller:
# config/initializers/devise.rb
config.scoped_views = true
rails generate devise:views users
# app/controllers/users/registrations_controller.rb
#
# NOTE: I created this class, so creating new users could only be done by authenticated users.
#
class Users::RegistrationsController < Devise::RegistrationsController
before_filter :authenticate_user!
prepend_before_filter :authenticate_scope!
skip_before_filter :require_no_authentication
end
# app/controllers/users/sessions_controller.rb
# (currently empty)
class Users::SessionsController < Devise::SessionsController
end
The problem:
Why devise is ignoring the :path_names settings above in some situations?
For example, this method will not use the :sign_in setting above, and returns an incorrect path:
new_session_path(resource_name)
=> /users/sign_in
resource_name
=> user
Whereas this method returns the correct path:
new_user_session_path
=> /users/login
The problem is, Devise internally uses the former method, and keeps redirecting to the wrong path when the user is not signed in.
Have I mis-configured something, or is Devise not working correctly? Could this be a Rails 4 issue?

I'm not sure what the issue I was having was. (I'd still be interested to know, if anyone knows).
But I've found another way to express what I wanted with devise, and it seems to work OK:
devise_for :users,
:controllers => {
:registrations => 'users/registrations'
},
:path_names => {
:sign_up => 'new'
}, :skip => [:sessions]
as :user do
get '/users/login' => 'devise/sessions#new', :as => :new_user_session
post '/users/login' => 'devise/sessions#create', :as => :user_session
match '/users/logout' => 'devise/sessions#destroy', :as => :destroy_user_session,
:via => Devise.mappings[:user].sign_out_via
end

I think you trying to solve your question with the wrong feature, in this link show you how to write another routes for devise, in my app I've recreated the routes with this:
devise_scope :user do
get '/cadastrar' => 'devise/registrations#new'
get '/entrar' => 'devise/sessions#new'
get '/editar' => 'devise/registrations#edit'
delete '/sair' => 'devise/sessions#destroy'
end
I'm glad if work!

Related

Rails 4 + Devise: Missing "admins/sign_up" route

I have a Rails app, v4, and just need ot modify some "old" code - I need to add some attributes to the admin model.
When I tried to add a new admin user and set to the browser "/admins/sign_up", I got an error message that the route doesn't exist.
Okay, so I checked all the Devise routes:
new_admin_session GET /admins/sign_in(.:format) devise/sessions#new
admin_session POST /admins/sign_in(.:format) devise/sessions#create
destroy_admin_session DELETE /admins/admin_logout(.:format) devise/sessions#destroy
admin_password POST /admins/password(.:format) devise/passwords#create
new_admin_password GET /admins/password/new(.:format) devise/passwords#new
edit_admin_password GET /admins/password/edit(.:format) devise/passwords#edit
PATCH /admins/password(.:format) devise/passwords#update
PUT /admins/password(.:format) devise/passwords#update
new_user_session GET /users/login(.:format) devise/sessions#new
user_session POST /users/login(.:format) devise/sessions#create
destroy_user_session DELETE /users/logout(.:format) devise/sessions#destroy
user_password POST /users/secret(.:format) devise/passwords#create
new_user_password GET /users/secret/new(.:format) devise/passwords#new
edit_user_password GET /users/secret/edit(.:format) devise/passwords#edit
PATCH /users/secret(.:format) devise/passwords#update
PUT /users/secret(.:format) devise/passwords#update
How is possible that the routes for a new admin sign up is missing? Did I miss something?
Anyway, how to add this missing route?
When I look to the views, I see that in admins/registrations/ is new.html.erb and there's a sign up form for a new admin.
How to display (under which URL) form and use it?
Thank you in advance.
EDIT: Routes
devise_for :admins, :path_names => {:sign_out => 'admin_logout'}
devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret',
:confirmation => 'verification', :unlock => 'unlock', :registration => 'register',
:sign_up => 'signup' }, :controllers => {:omniauth_callbacks => "omniauth_callbacks", :registrations => "registrations"}
You can add the missing /admins/sign_up route like the following:
devise_for :admins do
get '/admins/sign_up' => 'devise/registrations#new'
end
This generates this route:
new_admin_registration GET /admins/sign_up(.:format) devise/registrations#new
and should fix your problem.
Update:
Remove this from your current routes file:
devise_for :admins, :path_names => {:sign_out => 'admin_logout'}
Add this to your routes file:
devise_for :admins do
get '/admins/sign_up' => 'devise/registrations#new'
end

How to use Devise both in the site and in the Admin Pages

I'm new to RoR and Devise and i'm stuck in User Authentications with Devise. I'm developing a web site, which has admin pages in it. My structure looks like this:
app
|-controllers
|-admin
|- user_list_controller.rb //Every user crud operations are in it.
|-views
|-admin
|-user_list
|-new.html.erb
|-edit.html.erb
|-devise //Also have devise views
UserListController:
class Admin::UserListController < ApplicationController
layout 'admin/admin'
def index
#user_list = User.all
end
def new
#user = User.new
end
def edit
end
def delete
end
def create_user
end
end
What I want to do is that, I want to use Devise methods under this controller but this is where I stuck in. I created a UserController which base is Devise::RegistrationsController. But this time I got this error,
Could not find devise mapping for path "/admin/create_user". This may
happen for two reasons: 1) You forgot to wrap your route inside the
scope block. For example: devise_scope :user do get "/some/route" =>
"some_devise_controller" end 2) You are testing a Devise controller
bypassing the router. If so, you can explicitly tell Devise which
mapping to use: #request.env["devise.mapping"] =
Devise.mappings[:user]
It looks like a route.rb error and my route file is:
Rails.application.routes.draw do
devise_for :users
devise_scope :user do
# post "admin/add_user" =>"admin/user_list#create_user", as: :adduser
end
namespace :admin do
root to: 'admin#index'
get 'user_list', :to => 'user_list#index'
post 'create_user', :to => "user#create"
get 'new_user', :to => 'user_list#new'
get 'user_proposals', :to => 'user_proposal_forms#index'
get 'user_appointments', :to => 'user_appointments#index'
get 'brands', :to => 'brands#index'
get 'brand_makes', :to => 'brand_makes#index'
get 'make_types', :to => 'make_types#index'
end
end
And the result of rake routes is this:
Prefix Verb URI Pattern Controller#Action new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format)devise/registrations#new edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
admin_root GET /admin(.:format) admin/admin#index
admin_user_list GET /admin/user_list(.:format) admin/user_list#index
admin_create_user POST /admin/create_user(.:format) admin/user#create
admin_new_user GET /admin/new_user(.:format) admin/user_list#new
admin_user_proposalsGET /admin/user_proposals(.:format) admin/user_proposal_forms#index
admin_user_appointments GET /admin/user_appointments(.:format) admin/user_appointments#index
admin_brands GET /admin/brands(.:format) admin/brands#index
admin_brand_makes GET /admin/brand_makes(.:format) admin/brand_makes#index
admin_make_types GET /admin/make_types(.:format) admin/make_types#index
It looks messy, sorry for that. Finally my form_for looks like this:
<%= simple_form_for #user, url: admin_create_user_path, class: "form-horizontal" do |f| %>
<%= render(:partial => "form", :locals => {:f => f}) %>
<% end %>
So where did I make a mistake? I've read all the documents in Devise, tried so many things but couldn't solve the problem.
In routes file use
devise_for :users, :controllers => { registrations: 'registrations' }

Devise after_sign_in_path_for works, but not the other ones

I'm really missing something here.
I have read many things about devise redirects (seems like it is hard to implement for most people ...) but in my case I really don't get it.
Sometimes I read that the methods after_<action>_path_for(resource) should be in the ApplicationController, sometimes it is mentionned to be in a specific controller, overriding the devise one.
I'd rather have them in my ApplicationController since it bothers me to create more Controllers just for a redirect, but if it is not possible at the end, I won't insist...
Here's the deal:
I have in my ApplicationController : (and some others, but that's enough for the example)
def after_update_path_for(user)
flash[:notice] = 'Successfully updated password'
edit_user_path(user)
end
def after_inactive_sign_up_path_for(user)
flash[:notice] = 'Welcome! Please follow the steps!'
me_new_path
end
def after_sign_up_path_for(user)
flash[:notice] = 'Welcome! Please follow the steps!'
me_new_path
end
def after_sign_in_path_for(user)
if user.sign_in_count == 1
me_new_path
else
root_path
end
end
And the crazy thing, is that after_sign_in_path_for is called, but not the other ones. Like when the user signs up it's the if user.sign_in_count == 1 that redirects him, not the after_inactive_sign_up_path_for nor the after_sign_up_path_for
How come?
It could be related to my routes, so here's my routes.rb extract:
devise_for :user, :skip => [:sessions, :registrations], :path => ''
devise_scope :user do
get :register, :to => 'devise/registrations#new'
post :register, :to => 'devise/registrations#create'
put :update_password, :to => 'devise/my_registrations#update'
get :login, :to => 'devise/sessions#new'
get :login, :to => 'devise/sessions#new', :as => :new_copasser_session
post :login, :to => 'devise/sessions#create'
delete :logout, :to => 'devise/sessions#destroy'
end
And I'm using Devise 3.1.0 with Ruby 1.9.3 and Rails 3.2.13
Thanks for the help!
EDIT
Thanks #rich-peck for your answer. I updated my routes.rb this way :
devise_for :users, :path => '', :path_names => {
:sign_in => :login,
:registration => :register,
:sign_up => '',
:sign_out => :logout
}
which gives me the same routes as the previous ones (except I can't use login_path helper anymore but it's not a big deal), but I still get the same results concerning redirects.
Here is the result of rake routes:
new_user_session GET /login(.:format) devise/sessions#new
user_session POST /login(.:format) devise/sessions#create
destroy_user_session DELETE /logout(.:format) devise/sessions#destroy
user_password POST /password(.:format) devise/passwords#create
new_user_password GET /password/new(.:format) devise/passwords#new
edit_user_password GET /password/edit(.:format) devise/passwords#edit
PUT /password(.:format) devise/passwords#update
cancel_user_registration GET /register/cancel(.:format) devise/registrations#cancel
user_registration POST /register(.:format) devise/registrations#create
new_user_registration GET /register(.:format) devise/registrations#new
edit_user_registration GET /register/edit(.:format) devise/registrations#edit
PUT /register(.:format) devise/registrations#update
DELETE /register(.:format) devise/registrations#destroy
user_confirmation POST /confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /confirmation/new(.:format) devise/confirmations#new
GET /confirmation(.:format) devise/confirmations#show
Any idea?
Devise relies heavily on a central variable called "resource". This variable defines how devise operates on your system, and is why you have to "attach" Devise to :users or similar
People get problems with Devise because they don't follow the conventions, and put their forms everywhere. If they read the Devise readme, they'd appreciate that it's quite flexible :)
I believe your problem is to do with your routes, in that you might want to consolidate all those static routes into something like this:
devise_for :users, :path => '', :controllers => {:sessions => 'sessions', :registrations => 'registrations'}, :path_names => { :sign_in => 'login', :password => 'forgot', :confirmation => 'confirm', :unlock => 'unblock', :registration => 'register', :sign_up => 'new', :sign_out => 'logout'}
So thanks to #rich-peck's help, we figured it out.
The question was why do after_sign_in_path_for behave differently than after_sign_up_path_for and cie ?
It appears, in the devise sources, that after_sign_in_path_for is defined in a helper, whereas the other ones are methods of their controller (eg. Devise::RegistrationsController < DeviseController)
Hence for after_sign_in_path_for it works overriding in the ApplicationController, whereas for the other ones, it is necessary to create a registrations_controller.rb file, to override the method in it:
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(copasser)
flash[:notice] = 'Welcome! Please follow the steps!'
me_new_path
end
end
and to set the router.rb this way:
devise_for :copassers, :controllers => {
:registrations => :registrations
}
I suppose the behaviour is different because :registerable, :recoverable etc. are modules of devise, not necessarily used, and the helper wouldn't be appropriate in that case. A devise contributor could help us on this point.

How-to: Devise after_sign_up_redirect?

I tried to follow the instructions here (GitHub Devise Wiki) but it's not working for me.
I'm trying to get Devise to redirect to /welcome after user signs up. I created a Registrations controller but it's never going into the view. What am I doing wrong here?
Ruby 1.9.2
Rails 3.1.0.rc4
Devise 1.4.2
Thank you
UPDATE:
For some reason after_sign_up_path_for is not triggered but after_sign_in_path_for is triggered. I would still like to get after_sign_up_path_for to work though
_app/controllers/registrations_controller.rb_
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
welcome_path
end
end
Here's my config/routs.rb
MyApp::Application.routes.draw do
devise_for :users
root :to => 'pages#home'
match "/users", :to => "users#all"
match "/users/:id", :to => "users#show", :as => :user
match "/welcome", :to => "users#welcome", :as => :user
devise_for :users, :controllers => { :registrations => "registrations" } do
get "/login", :to => "devise/sessions#new"
get "/register", :to => "devise/registrations#new"
get "/logout", :to => "devise/sessions#destroy"
get '/account' => 'devise/registrations#edit'
end
end
Output from rake routes
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_omniauth_callback /users/auth/:action/callback(.:format) {:action=>/(?!)/, :controller=>"devise/omniauth_callbacks"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
root / {:controller=>"pages", :action=>"home"}
users /users(.:format) {:controller=>"users", :action=>"all"}
user /users/:id(.:format) {:controller=>"users", :action=>"show"}
user /welcome(.:format) {:controller=>"users", :action=>"welcome"}
login GET /login(.:format) {:controller=>"devise/sessions", :action=>"new"}
register GET /register(.:format) {:controller=>"devise/registrations", :action=>"new"}
logout GET /logout(.:format) {:controller=>"devise/sessions", :action=>"destroy"}
account GET /account(.:format) {:controller=>"devise/registrations", :action=>"edit"}
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_omniauth_callback /users/auth/:action/callback(.:format) {:action=>/(?!)/, :controller=>"devise/omniauth_callbacks"}
POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
GET /users/cancel(.:format) {:action=>"cancel", :controller=>"registrations"}
POST /users(.:format) {:action=>"create", :controller=>"registrations"}
GET /users/sign_up(.:format) {:action=>"new", :controller=>"registrations"}
GET /users/edit(.:format) {:action=>"edit", :controller=>"registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"registrations"}
You have devise_for :users twice in your routes.rb. Change the routes.rb as follows:
MyApp::Application.routes.draw do
devise_for :users, :controllers => { :registrations => "registrations" } do
get "/login", :to => "devise/sessions#new"
get "/register", :to => "devise/registrations#new"
get "/logout", :to => "devise/sessions#destroy"
get '/account' => 'devise/registrations#edit'
end
root :to => 'pages#home'
match "/users", :to => "users#all"
match "/users/:id", :to => "users#show", :as => :user
match "/welcome", :to => "users#welcome", :as => :user
end
If you have activation/deactivation logic, you have to override after_inactive_sign_up_path_for too as mentioned in the devise wiki. Can you tell where it is getting redirected to after sign up?
The reason why after_sign_in_path_for is working may be that you have the same sessions_controller and different registrations_controller, so sign-in works as you expected and the registrations route is getting blocked because you have defined it twice, so all the registration requests and actions are executed in the devise/registrations rather than your custom registrations controller.
So remove that, change the routes.rb as mentioned above, and see what happens.
Your devise_for looks kind of odd. The after_sign_up_path_for should go fine as a public method in your application_controller.rb
Change your routes file to just be devise_for :users, as well as placing after_sign_up_path_for in your application_controller.rb
You have duplicate devise_for listings in your routes.rb file. Try removing the first one, the simple devise_for :users, and leaving only the second one.
In my application I have the after_sign_in_path_for method in my application_controller.rb file. Try putting it in there, restarting your server and see if that makes any difference. Also, I don't have my method listed under protected but rather private.
If you want to redirect users to a welcome page after signup, it sounds like you just want to redirect them after a successful user create. So your users_controller would look something like this:
class UsersController < ApplicationController
def new
#user = User.new
end
def create
#user = User.new(params[:user])
if #user.save
flash[:notice] = "Registration successful."
redirect_to welcome_path
else
render :action => 'new'
end
end
def show
#user = User.find(params[:id])
end
def edit
#user = User.find(params[:id])
end
def update
#user = User.find(params[:id])
if #user.update_attributes(params[:user])
flash[:notice] = "Successfully updated user."
redirect_to #user
else
render :action => 'edit'
end
end
end
The instructions worked fine for me (new Registrations controller, modify routes.rb and copy the registrations views to app/view/registrations) but I needed to change my routes.rb slightly so that registrations controllers was picked up. Order is important as the first matching route is going to be used - and you want that to be the new registration route.
devise_for :users, :controllers => { :registrations => "registrations" }
devise_for :users
(make sure devise_for :users comes after the new route for registrations)
https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb#L82

Devise Custom Routes and Login Pages

I'm trying to get Custom Routes working in my Rails application (Ruby 1.9.2 with Rails 3).
This is my config/routes.rb file
match '/dashboard' => 'home#dashboard', :as => 'user_root'
devise_for :user do
get "/login", :to => "devise/sessions#new" # Add a custom sign in route for user sign in
get "/logout", :to => "devise/sessions#destroy" # Add a custom sing out route for user sign out
get "/register", :to => "devise/registrations#new" # Add a Custom Route for Registrations
end
But submitting the form on /login or /register goes to users/sign_in
and users/sign_up. How do I prevent this from happening. Or even better make sure that by default all requests for users/sign_in etc go to the relevant routes and not the default routes generated by Devise.
Also how can I make the login form a partial to include it in any controller? So that I can have the Login Page on the homepage (home#index) and not on users/sign_in?
I'm using Devise 1.1.3 with Rails 3 on Ruby 1.9.2, on Mac OSX Snow Leopard.
Thanks!
With Devise 1.1.3 the following should work
devise_for :user, :path => '', :path_names => { :sign_in => "login", :sign_out => "logout", :sign_up => "register" }
The routes it creates will not be appended with "/user/..." because of the :path parameter being an empty string. The :pathnames hash will take care of naming the routes as you like. Devise will use these routes internally so submitting to /login will work as you wish and not take you to /user/log_in
To add a login form to your front page there's info at the Devise Wiki:
http://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app
Or do something like this:
<%= form_tag new_user_session_path do %>
<%= text_field_tag 'user[email]' %>
<%= password_field_tag 'user[password]' %>
<%= submit_tag 'Login' %>
The following worked for me:
devise_for :users do
get "/login" => "devise/sessions#new"
get "/register" => "devise/registrations#new"
end
Config:
devise_scope :user do
get 'profile/edit' => 'devise/registrations#edit', :as => :edit_user_registration
get 'profile/cancel' => 'devise/registrations#cancel', :as => :cancel_user_registration
end
devise_for :users,
:path => '',
:path_names => { :sign_in => 'login',
:sign_out => 'logout',
:sign_up => '',
:registration => 'register',
:edit => 'edit',
:cancel => 'cancel',
:confirmation => 'verification' }
Routes:
edit_user_registration GET /profile/edit(.:format) devise/registrations#edit
cancel_user_registration GET /profile/cancel(.:format) devise/registrations#cancel
new_user_session GET /login(.:format) devise/sessions#new
user_session POST /login(.:format) devise/sessions#create
destroy_user_session DELETE /logout(.:format) devise/sessions#destroy
user_password POST /password(.:format) devise/passwords#create
new_user_password GET /password/new(.:format) devise/passwords#new
edit_user_password GET /password/edit(.:format) devise/passwords#edit
PATCH /password(.:format) devise/passwords#update
PUT /password(.:format) devise/passwords#update
GET /register/cancel(.:format) registrations#cancel
user_registration POST /register(.:format) registrations#create
new_user_registration GET /register(.:format) registrations#new
GET /register/edit(.:format) registrations#edit
PATCH /register(.:format) registrations#update
PUT /register(.:format) registrations#update
DELETE /register(.:format) registrations#destroy
You just need don't put your special route in devise_for block
match '/dashboard' => 'home#dashboard', :as => 'user_root'
get "/login", :to => "devise/sessions#new" # Add a custom sign in route for user sign in
get "/logout", :to => "devise/sessions#destroy" # Add a custom sing out route for user sign out
get "/register", :to => "devise/registrations#new" # Add a Custom Route for Registrations
devise_for :user
Now /login works. /users/sign_in too.
I created my own auth controller and routed devise sessions controller to my controller
devise_for :users,
:controllers => {
:sessions => 'auth' },
:path => '/',
:path_names => {
:sign_in => 'login',
:sign_out => 'logout' }
This code will add /login and /logout urls.
More about this you can find in source code http://github.com/plataformatec/devise/blob/master/lib/devise/rails/routes.rb
Use this at the top of your routes.rb file
map.connect "users/:action", :controller => 'users', :action => /[a-z]+/i
use this on where your index file is. if it is on your users model, use the above or change accordingly

Resources