Devise links / routes getting mixed up with non devise model?

The problem is with 'devise' namespace. When you use link creation this way.

Up vote 0 down vote favorite 1 share g+ share fb share tw.

I am using Devise in an app for the first time and I am having a weird problem I cant understand: I've created my User model with Devise, and setup all the registration, user sign-up, etc, and everything works fine. In my application header, I have my nav menu (which is currently empty) and a partial with log in, sign out, etc: _header.html. Erb 'brand' %> _user_options.html.

Erb :delete %> Now I am adding the first link to the nav menu, if I use: Everything is fine. BUT if I use: 'tasks', :action => 'index' %> When I click on any of the Devise links, such as 'Sign in', I get 'No route matches {:controller=>"devise/tasks"}' By request on the comments, here is the output of rake routes: Tasks: TOP => routes => environment (See full trace by running task with --trace) MacBook-Pro-de-o:dearsherpa Oscar$ bundle exec rake routes tasks_index GET /tasks/index(.:format) {:controller=>"tasks", :action=>"index"} tasks_show GET /tasks/show(.:format) {:controller=>"tasks", :action=>"show"} 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_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" and here is routes. Rb: get "tasks/index" get "tasks/show" devise_for :users root :to => 'pages#home' Why is this?

What I am doing wrong? Edit2: By the way, I forgot mentioning that Task belongs_to User, and the User model has been generated by devise. Which probably is whats causing this.

Can't I access /tasks/index without /user/id/tasks/? Edit: more weird stuff, I tried using resources :tasks in my routes file, instead of the 'get' routes for that controller, and now when I click on 'tasks', :action => 'index' %> it takes me to the show action. So something is really wrong with my routes, apparently.

Ruby-on-rails devise link|improve this question edited Dec 8 '11 at 0:51 asked Dec 2 '11 at 23:18agente_secreto462319 79% accept rate.

Run: rake routes and copy paste the result here. – daniel Dec 8 '11 at 0:09 can you post the code from routes. Rb and run rake routes please?

– stephenmurdoch Dec 8 '11 at 0:10 Done, I edited my question – agente_secreto Dec 8 '11 at 0:28 You're routes were correct: heres the route tasks_index GET /tasks/index(.:format) {:controller=>"tasks", :action=>"index"} . Now show us the html generated by 'tasks', :action => 'index' %> and also – daniel Dec 8 '11 at 5:01.

The problem is with 'devise' namespace. When you use link creation this way: 'tasks', :action => 'index' %> then the route is generated from the current namespace, which is 'devise' when you click any devise link. To avoid this behavior, you can either use the route this way: '/tasks', :action => 'index' %> or use helpers, which work correctly in this situation (tasks_index_path in case of 'get "tasks/index"' in routes.

Rb, or tasks_path in case of resources :tasks).

Indeed, I would recommend using . That should always work. – nathanvda Dec 9 '11 at 22:37 Sounds like a good solution, but could you clarify if this is a Devise specific problem or Rails standard behaviour?

I've been working with Rails for a while now and never before came across this problem – agente_secreto Dec 10 '11 at 20:03 That's common rails behaviour. Actually could not find a doc corresponding to this feature quickly, but tried it with the common user defined namespace - the routes work the same way as in your example – alony Dec 11 '11 at 18:09.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions