Custom Controller

522 views
Skip to first unread message

bk

unread,
Apr 15, 2010, 7:52:27 AM4/15/10
to Devise
Hi,

I have been trying to use device 1.1rc1 on rails 3 beta3 and stuck
with following issue. I have a login box on my company home page. So I
have created a homeController with an index method. Here's my
HomeController and routes.rb

--------------- routes.rb -----------------------
Application::Application.routes.draw do |map|
devise_for :users, :controllers => { :sessions => "home" }

resources :home, :only => :index

root :to => "home#index"
end

-------------------- app/controllers/HomeController.rb
-----------------------
class HomeController < Devise::SessionsController
# prepend_before_filter :require_no_authentication, :only =>
[ :new, :create ]
# include Devise::Controllers::InternalHelpers

# GET /resource/sign_in
def index
end

end

For now I have kept my view very simple. However, on execution I am
getting "Unknown action
AbstractController::ActionNotFound"

It will really help if someone can assist me to resolve this issue.

Regards
Bhavin

Matthieu Dubet

unread,
Apr 19, 2010, 4:58:57 PM4/19/10
to Devise
Hi,
I need to add some method to the sessioncontroller, but the readme
isn't really clear about custom controllers .

I have an User model

For the moment , i have (unsuccessfully) tried :
# config/routes

devise_for :users, :controllers => { :sessions => 'user/sessions' }
# app/model/users_controller.rb

class Users::SessionsController < Devise::SessionsController
end

And i get : uninitialized constant User::SessionsController


--
Subscription settings: http://groups.google.com/group/plataformatec-devise/subscribe?hl=en

Carlos A. da Silva

unread,
Apr 19, 2010, 6:31:21 PM4/19/10
to Devise
@Matthieu, notice you're pointing your routes to 'user/sessions', and
not 'users/sessions', in plural. It is trying to find a controller as
User::SessionsController, not Users::SessionsController.
In addition, you can open new threads for your questions, as it's not
related to this one okay =).

--
Carlos Antonio

charper

unread,
May 13, 2010, 9:42:55 AM5/13/10
to Devise
Did you find a solution to this problem as I also face this issue

routes.rb
map.devise_for :users , :controllers => {:sessions => '/users/
sessions'}

controllers/sessions_controller.rb
class Users::SessionsController < Devise::SessionsController
end


Will result in : uninitialized constant Users

José Valim

unread,
May 13, 2010, 10:00:36 AM5/13/10
to plataforma...@googlegroups.com
The controller name should be pluralized and properly placed. This means:

# config/routes.rb
   map.devise_for :users , :controllers => {:sessions => 'users/
sessions'}

# app/controllers/users/sessions_controller.rb

    class Users::SessionsController < Devise::SessionsController
    end

--
José Valim

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

charper

unread,
May 13, 2010, 11:32:25 AM5/13/10
to Devise
Using your solution results in the controller never being called (from
what I can tell).

The request however is as follows :

Processing SessionsController#new (for 127.0.0.1 at 2010-05-13
16:20:38) [GET]
Parameters: {"action"=>"new", "controllers"=>{"sessions"=>"users/
sessions"}, "controller"=>"sessions"}


Relevant information :

map.devise_for :users ,:controllers => {:sessions => 'users/
sessions'}
map.root :controller=>"sessions", :action => "new"
map.sign_out "/logout", :controller=>"sessions", :action =>
"destroy"

app/controllers/users/sessions_controller.rb

class Users::SessionsController < Devise::SessionsController
def new
end
end

devise.rb (default other than)
config.scoped_views = false
config.use_default_scope = true
config.default_scope = :user

I've tried altering the fields in devise.rb with no success.

Truly puzzled :/
On May 13, 3:00 pm, José Valim <jose.va...@gmail.com> wrote:
> The controller name should be pluralized and properly placed. This means:
>
> *# config/routes.rb*
>    map.devise_for :users , :controllers => {:sessions => 'users/
> sessions'}
>
> *# app/controllers/users/sessions_**controller.rb*

José Valim

unread,
May 13, 2010, 11:35:36 AM5/13/10
to plataforma...@googlegroups.com
Sorry, but it won't work on Rails 2.3. This is a Devise 1.1 feature.

charper

unread,
May 13, 2010, 11:48:56 AM5/13/10
to Devise
This would explain it :)

Pity other gems I need are not Rails v3 compliant yet .

Thanks for your help.

Maxim Filatov

unread,
Aug 12, 2010, 7:02:59 AM8/12/10
to plataforma...@googlegroups.com
On May 13, 2010, at 6:00 PM, José Valim wrote:

The controller name should be pluralized and properly placed. This means:

# config/routes.rb
   map.devise_for :users , :controllers => {:sessions => 'users/
sessions'}

# app/controllers/users/sessions_controller.rb
    class Users::SessionsController < Devise::SessionsController
    end

Does it work in Devise-1.0?

# app/controllers/users/sessions_controller.rb
class Users::SessionsController < Devise::SessionsController
end

#config/routes.rb
...
  map.devise_for :users, :controllers => {:sessions => 'users/sessions'}
...


Error:
/Users/bregor/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:443:in `load_missing_constant': uninitialized constant Devise::SessionsController (NameError)
from /Users/bregor/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `const_missing'


Devise-1.0.8
Rails-2.3.8


---
Best regards,
Maxim Filatov

Carlos Antonio da Silva

unread,
Aug 12, 2010, 8:03:43 AM8/12/10
to plataforma...@googlegroups.com
Nope, this does not work in Devise 1.0.x, it's only a Devise 1.1.x feature.
--
At.
Carlos A. da Silva

Maxim Filatov

unread,
Aug 12, 2010, 8:24:10 AM8/12/10
to plataforma...@googlegroups.com

On Aug 12, 2010, at 4:03 PM, Carlos Antonio da Silva wrote:

> Nope, this does not work in Devise 1.0.x, it's only a Devise 1.1.x feature.

Ok
Thanks for the answer!

Reply all
Reply to author
Forward
0 new messages