devise_for route helper broken for namespaced models

303 views
Skip to first unread message

Nicholas Faiz

unread,
Aug 13, 2010, 10:56:42 PM8/13/10
to Devise
Hello,

I'm learning how to use Devise, very new, so this might be something
I'm overlooking.

I have a users model which is nested in a module - Inkling::Users .
The nesting is necessary as I'm building an engine which plugs into
other apps which will likely have their own model called User.

I've configured routes as:

devise_for "inkling/users", :controllers => { :sessions => "inkling/
sessions"}

This seems to generate a broken method:

/Users/nicholas/.rvm/gems/ruby-1.8.7-p299/gems/actionpack-3.0.0.rc/lib/
action_dispatch/routing/route_set.rb:163:in `define_hash_access':
compile error (SyntaxError)
/Users/nicholas/.rvm/gems/ruby-1.8.7-p299/gems/actionpack-3.0.0.rc/lib/
action_dispatch/routing/route_set.rb:161: syntax error, unexpected
'/', expecting '\n' or ';'
... def hash_for_new_inkling/user_session_path(options = ni...
^
/Users/nicholas/.rvm/gems/ruby-1.8.7-p299/gems/actionpack-3.0.0.rc/lib/
action_dispatch/routing/route_set.rb:163: syntax error, unexpected
kEND, expecting $end
end



Any idea how I can setup the route?

Cheers,
Nicholas

José Valim

unread,
Aug 13, 2010, 10:58:41 PM8/13/10
to plataforma...@googlegroups.com
Your devise_for call is wrong, try something like this:

 devise_for :users, :controllers => { :sessions => "inkling/sessions"}

And see if this is the result you expect by running `rake routes`. If not, play a bit more with the options in the documentation.

Cheers!

--
José Valim

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

Nicholas Faiz

unread,
Aug 13, 2010, 11:34:19 PM8/13/10
to Devise
Thanks Jose.

I ended up using

namespace :inkling do
devise_for "users", :controllers => { :sessions => "inkling/
sessions"}
end

Cheers,
Nicholas



On Aug 14, 12:58 pm, José Valim <jose.va...@gmail.com> wrote:
> Your devise_for call is wrong, try something like this:
>
>  devise_for :users, :controllers => { :sessions => "inkling/sessions"}
>
> And see if this is the result you expect by running `rake routes`. If not,
> play a bit more with the options in the documentation.
>
> Cheers!
>
> --
> José Valim
>
> Director of Engineering - Plataforma Tecnologia
> Know more about us:http://plataformatec.com.br/en/
>

Nicholas Faiz

unread,
Aug 14, 2010, 12:18:37 AM8/14/10
to Devise
Actually, this doesn't work. The route looks correct, but it depends
upon app/models/user.rb being present.

It doesn't seem possible to specify a namespaced model with the devise
route helper. I can fallback to creating routes by hand, but I'm
looking through the Devise code (in mapping.rb, particularly) and it
seems it should be possible. Using the namespace route above, the
mapping does have all the necessary information to work out that the
class name is Inkling::User ....

/Users/nicholas/.rvm/gems/ruby-1.8.7-p299/gems/devise-1.1.1/lib/
devise.rb:200
mapping = Devise::Mapping.new(resource, options)
(rdb:1) p options
{:module=>"inkling", :controllers=>{:sessions=>"inkling/
sessions"}, :as=>"inkling", :path_names=>{:edit=>"edit", :new=>"new"}, :path_prefix=>"/
inkling"}
(rdb:1) p resource
:users

Is this something you'd like to support? It's probably as simple as
building the class_name with the module.

Cheers,
Nicholas

Nicholas Faiz

unread,
Aug 14, 2010, 12:47:43 AM8/14/10
to Devise
Found the class_name option.

namespace :inkling do
devise_for "users", :controllers => { :sessions => "inkling/
sessions"}, :class_name => "Inkling::User"
end

Cheers!
Reply all
Reply to author
Forward
0 new messages