Ruby-on-rails – Problems with “devise_for”, “devise_scope”!

deviseruby-on-railsruby-on-rails-3

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

Best Answer

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.

Related Topic