Custom routing using devise

331 views
Skip to first unread message

Andrew Romanov

unread,
Apr 1, 2010, 4:46:05 PM4/1/10
to Devise
Hello. I want to have /login route instead of /users/sign_in. I am
using Ubuntu 9.10, rails3 edge, devise edge. I found out that to make
that work I have to set config.use_default_scope in "config/
initializers/devise.rb" to true . I could set config.default_scope
= :user, but I have actually only one model that uses devise gem. When
I set routes to

map.sign_in "/login", :controller => "sessions", :action => "new"
or
match "/login" => "sessions#new", :as => :sign_in

I actually get -
Routing Error
uninitialized constant SessionsController

Is something wrong with rails and Engines or I am doing something
wrong? Thanks.

P.S.
I already had one question about devise and here is the result
http://wiki.github.com/plataformatec/devise/custom-field-for-sign-in
Will be glad to help in advise

Carlos A. da Silva

unread,
Apr 1, 2010, 5:12:59 PM4/1/10
to Devise
Hello Andrew,

You really need to set config.default_scope to your unique scope as
well (for instance :user), to let Devise/Warden know about it.
And you also don't need to setup the routes by yourself, by using
default_scope, Devise/Warden will use this scope when you request /
sign_in for instance. But if you really want/need to do it,
controllers are under Devise module, so you don't have
SessionsController, but Devise::SessionsController.

--
Carlos Antonio

On Apr 1, 5:46 pm, Andrew Romanov <judo....@gmail.com> wrote:
> Hello. I want to have /login route instead of /users/sign_in. I am
> using Ubuntu 9.10, rails3 edge, devise edge. I found out that to make
> that work I have to set config.use_default_scope in "config/
> initializers/devise.rb" to true . I could set   config.default_scope
> = :user, but I have actually only one model that uses devise gem. When
> I set routes to
>
> map.sign_in "/login", :controller => "sessions", :action => "new"
> or
> match "/login" => "sessions#new", :as => :sign_in
>
> I actually get -
> Routing Error
> uninitialized constant SessionsController
>
> Is something wrong with rails and Engines or I am doing something
> wrong? Thanks.
>
> P.S.

> I already had one question about devise and here is the resulthttp://wiki.github.com/plataformatec/devise/custom-field-for-sign-in

José Valim

unread,
Apr 2, 2010, 4:26:34 AM4/2/10
to plataforma...@googlegroups.com
Andrew,

Shouldn't it be:

match "/login" => "devise/sessions#new", :as => :sign_in

It changed on Devise master.

Regards,

--
To unsubscribe, reply using "remove me" as the subject.



--
José Valim

Director of Engineering - Plataforma Tecnologia
Know more about us: http://plataformatec.com.br/en/

Andrew Romanov

unread,
Apr 2, 2010, 4:28:53 PM4/2/10
to Devise
This works ok. Thanks. But there is one issue - when I try to put some
login information and make a mistake - route changes to /users/
sign_in. Is there a simple way to change that? I would like to have /
login all the time.

José Valim

unread,
Apr 2, 2010, 5:38:31 PM4/2/10
to plataforma...@googlegroups.com
If you do:

match "/login" => "devise/sessions#new", :as => :user_sign_in

Before or after devise_for, it *may* work. :)

Please let us know and if possible, add it to the Wiki. :)

Thanks!

Andrew Romanov

unread,
Apr 2, 2010, 6:16:44 PM4/2/10
to Devise
I am sorry, but this didn't work. I still get same /users/sign_in url.
Also I have found other problem - when I go to some page I am not
allowed to (as I am not logged in), I get /users/sign_in?
unauthenticated=true. I like tiny urls like /login ;) I will add this
to wiki if I solve this problem.

José Valim

unread,
Apr 3, 2010, 4:20:35 AM4/3/10
to plataforma...@googlegroups.com
Sorry, I told you wrong. You should use:

  match "/login" => "devise/sessions#new", :as => :new_user_session

But I'm afraid you should overwrite all three session routes:


You can also give :skip to routes.

  devise_for :users, :skip => :sessions

It won't generate routes for sessions, so you can generate your own. But you still need to provide the same named url routes.
Reply all
Reply to author
Forward
0 new messages