I'm trying to customize my routes in devise. I've tried to use devise_scope :user, but it dind't work. So I changed to devise_for, and skiped the custom routes (registrations, confirmations, passwords, session) and it worked. But then, an error show up in my views, when i wass calling "session_path" for example. It was making a form redirecting to "session.user", that makes no sense.
Here is the code:
#routes.rb devise_for :users, :path => '', :skip => [ :passwords, :registrations, :confirmations] do post "account/password", :to => "devise/passwords#create" get "account/password/new", :to => "devise/passwords#new", :as => "new_password" get "account/password/edit", :to => "devise/passwords#edit", :as => "edit_password" put "account/password", :to => "devise/passwords#update" post "account", :to => "users/registrations#create" get "sign_up", :to => "users/registrations#new" delete "account", :to => "users/registrations#destroy" post "confirmation", :to => "devise/confirmations#create" get "confirmation/new", :to => "devise/confirmations#new", :as => "new_confirmation" get "confirmation", :to => "devise/confirmations#show" end
New session view:
#users/sessions/new.html.erb = form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
Error:
No route matches {:action=>"new", :format=>:user, :controller=>"devise/passwords"}
What do I do? What happened to "devise_scope" doesn't work correctly (The error it was showing up was "Could not find devise mapping for ...")?
Thanks
What routes are being generated? Run rake routes to find out.
If you are not seeing the routes that you expect, try defining your custom routes on a as block after your devise_for statement. Such as
devise_for :users, skip => [ :passwords, :registrations, :confirmations]
as :user do
post "account/password" => "devise/passwords#create"
get "account/password/new" => "devise/passwords#new"
get "account/password/edit" => "devise/passwords#edit"
put "account/password" => "devise/passwords#update"
...
end
You might also need to customize the views to point to the new paths that you declared. Look at Devise wiki to find how to customize views.
I tested your routes and I got this on a rake routes
:
account_password POST /account/password(.:format) {:controller=>"devise/passwords", :action=>"create"}
new_password GET /account/password/new(.:format) {:controller=>"devise/passwords", :action=>"new"}
edit_password GET /account/password/edit(.:format) {:controller=>"devise/passwords", :action=>"edit"}
PUT /account/password(.:format) {:controller=>"devise/passwords", :action=>"update"}
account POST /account(.:format) {:action=>"create", :controller=>"users/registrations"}
sign_up GET /sign_up(.:format) {:action=>"new", :controller=>"users/registrations"}
DELETE /account(.:format) {:action=>"destroy", :controller=>"users/registrations"}
confirmation POST /confirmation(.:format) {:action=>"create", :controller=>"devise/confirmations"}
new_confirmation GET /confirmation/new(.:format) {:controller=>"devise/confirmations", :action=>"new"}
GET /confirmation(.:format) {:action=>"show", :controller=>"devise/confirmations"}
new_user_session GET /sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
So, I guess you should be using user_session_path
(without any argument) on your form_for
. If you put the user as an argument, Rails will think it is the format and it will not work.
try to add :controllers => { :passwords => "devise/passwords"}
option
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With