我刚刚在我的应用程序上安装了 Devise,我以前像 Michael Hartl 教程一样从头开始完成它。
目前我可以注册和注销。但是当我登录时它给出了一个错误:
No route matches [POST] "/sessions/user"
当我单击带有或不带有(正确)密码的登录/登录按钮时,就会发生这种情况。
我的路线文件是:
SampleApp::Application.routes.draw do
devise_for :users, path_names: { sign_in: "login", sign_out: "logout"}
resources :users do
resources :bookings, only: [:show]
end
resources :bookings
resources :sessions
# match '/signup', to: 'devise/registrations#new', via: :get
# match '/signin', to: 'devise/sessions#new', via: [:post, :get]
# match '/signout', to: 'devise/sessions#destroy', via: :delete
match '/admin', to: 'admin#new', via: :get
match "bookings/new", to: 'bookings#new', via: [:post, :get]
devise_scope :user do
root to: 'static_pages#home'
end
[编辑]
我的表单是设计的默认表单:
<h2>Sign in</h2>
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<% if devise_mapping.rememberable? -%>
<div><%= f.check_box :remember_me %>
<%= f.label :remember_me %></div>
<% end -%>
<div><%= f.submit "Sign in" %></div>
<% end %>
目前我在 Session Controller 和 Helper 上没有任何代码,就像 Michael Hartl 教程中那样
我关于 Sessions 的 rake 路线如下:
sessions GET /sessions(.:format) sessions#index
POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
edit_session GET /sessions/:id/edit(.:format) sessions#edit
session GET /sessions/:id(.:format) sessions#show
PATCH /sessions/:id(.:format) sessions#update
PUT /sessions/:id(.:format) sessions#update
DELETE /sessions/:id(.:format) sessions#destroy
[解决了]
我更新了路由文件
devise_scope :user do
root to: 'static_pages#home'
match '/sessions/user', to: 'devise/sessions#create', via: :post
end