ruby-on-rails – 没有路由匹配[POST]“/ sessions / user”

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 没有路由匹配[POST]“/ sessions / user”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我刚刚在我的应用程序上安装了Devise,我之前已经像迈克尔哈特教程那样做了一些.

目前我可以注册并注销.但是当我登录时会出现错误

没有路由匹配[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',: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 %>

目前,在Michael Hartl教程中,我没有关于Session Controller和Helper的任何代码

我关于Sessions的佣金路线如下:

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

解决方法

在routes文件添加以下行
post ':controller(/:action(/:id(.:format)))'
get ':controller(/:action(/:id(.:format)))'

删除匹配’:controller(/:action(/:id(.:format)))’ – >在以后的版本中导致冲突

原文链接:https://www.f2er.com/ruby/268835.html

猜你在找的Ruby相关文章