Could not find devise mapping for path “/sessions/user” devise log in error

我的未来我决定 提交于 2019-12-04 01:11:54
Wally Ali

in your routes.rb file, try wrapping your routes inside the scope block as the error message suggests. Here is an example:

devise_scope :user do
   get "signup", to: "devise/registrations#new"
   get "login", to: "devise/sessions#new"
   get "logout", to: "devise/sessions#destroy"
end

This will give you nicely named routes.

And by the way, if you are using Rails 4, get rid of the match method. you need to specify the HTTP verb.


OBSOLETE old answer:

(Below is the old obsolete version of the code, shown for reference. Use the code above.)

devise_for :users, path_names: { sign_in: 'login', sign_out: 'logout', sign_up: 'signup' }

AND

match '/sessions/user', to: 'devise/sessions#create', via: :post

Be careful if you nave namespaced routes to declare the devise_scope a little different:

namespace :api, defaults: {format: 'json'} do 
  namespace :v1 do 
    devise_scope :api_v1_user do
      ...
    end
  end
end

This error (AbstractController::ActionNotFound - Could not find devise mapping for path) can arise if devise_scope is passed a plural scope instead of a singular scope.

The devise_for method takes a plural form of model scope (i.e. :users) whereas the devise_scope takes the singular form (i.e. :user).

From the devise documentations (http://www.rubydoc.info/github/plataformatec/devise/ActionDispatch%2FRouting%2FMapper%3Adevise_scope):

Also be aware of that 'devise_scope' and 'as' use the singular form of the noun where other devise route commands expect the plural form. This would be a good and working example.

devise_scope :user do
  get "/some/route" => "some_devise_controller"
end
devise_for :users

Error is telling you:

devise_scope :user do
  match '/sessions/user', to: 'devise/sessions#create', via: :post
end

did you try that?

devise_scope :user do
  # add any route which is giving above error message
end 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!