ActionNotFound for root :to => "Devise::Sessions#new"

334 views
Skip to first unread message

moritz

unread,
Sep 20, 2010, 12:49:43 PM9/20/10
to Devise
I am trying to route to the sign_in page by using

DeviseExample::Application.routes.draw do
devise_for :users
root :to => "Devise::Sessions#new"

but get the following error (in devise 1.1.2):

Started GET "/" for 127.0.0.1 at 2010-09-20 09:42:28 -0700
Processing by Devise::SessionsController#new as HTML
Completed in 0ms

AbstractController::ActionNotFound
(AbstractController::ActionNotFound):

Using devise 1.2 that changes to:

Started GET "/" for 127.0.0.1 at 2010-09-20 09:20:21 -0700
Processing by Devise::SessionsController#new as HTML
[Devise] Could not find devise mapping for /.
Completed in 0ms

AbstractController::ActionNotFound (Could not find devise mapping
for /.):

How else can I accomplish this? Am I trying something impossible?


Carlos Antonio da Silva

unread,
Sep 22, 2010, 8:49:04 AM9/22/10
to plataforma...@googlegroups.com
I'm not sure pointing "/" to Devise session would be the best, cause every time a user access "/", if he's signed in, it's going to have a redirect.

--
At.
Carlos A. da Silva

moritz

unread,
Sep 27, 2010, 1:23:44 PM9/27/10
to Devise
You are right, that was backwards. After a bit of refactoring, I came
up with

devise_for :users
devise_scope :user do
root :to => "users#current"
get '/users/current' => "users#current", :as => :current_user
resources :users, :only => [:index, :show]
end

to do what I was looking for.

I could not use

devise_for :users do
root :to => "users#current"
get '/users/current' => "users#current", :as => :current_user
resources :users, :only => [:index, :show]
end

due to route ordering. '/users/:id(.:format)' would be before '/users/
sign_in(.:format)', for example.

There are still aspects that I don't understand. In particular, if I
use

devise_scope :users do ...

instead of

devise_scope :user do ...

I get the error

Started GET "/" for 127.0.0.1 at 2010-09-27 10:08:42 -0700
Processing by UsersController#current as HTML
Completed in 0ms

AbstractController::ActionNotFound
(AbstractController::ActionNotFound):

even though routes look exactly the same.

Any further insight would certainly be welcome. Thanks in advance.

On Sep 22, 5:49 am, Carlos Antonio da Silva
<carlosantoniodasi...@gmail.com> wrote:
> I'm not sure pointing "/" to Devise session would be the best, cause every
> time a user access "/", if he's signed in, it's going to have a redirect.
>
> Take a look on the wiki here to have some more info:http://github.com/plataformatec/devise/wiki/How-To:-Change-the-defaul...

Carlos Antonio da Silva

unread,
Sep 27, 2010, 9:30:49 PM9/27/10
to plataforma...@googlegroups.com
That's because Devise uses the singular name as it's mapping name, so you'll always end up with :user as the scope. In devise_scope / authenticate methods you need give the scope itself, Devise won't try to find it.
Reply all
Reply to author
Forward
0 new messages