简体   繁体   English

设计路由错误:没有路由与[GET]“ / users / sign_out”匹配

[英]Devise routing error: No route matches [GET] “/users/sign_out”

routes.rb => route.rb =>

  devise_for :users

  resources :posts
  match "posts/:id/categ" => "posts#categ"
  match "posts/:id/tag_posts" => "posts#tag_posts"
  match "posts/searcharchive" => "posts#searcharchive"
  #post "posts/searcharchive"

  resources :categories
  resources :comments
  resources :countpages

rake routes => 耙路=>

        new_user_session GET    /users/sign_in(.:format)       {:action=>"new", :controller=>"devise/sessions"}
            user_session POST   /users/sign_in(.:format)       {:action=>"create", :controller=>"devise/sessions"}
    destroy_user_session DELETE /users/sign_out(.:format)      {:action=>"destroy", :controller=>"devise/sessions"}
           user_password POST   /users/password(.:format)      {:action=>"create", :controller=>"devise/passwords"}
       new_user_password GET    /users/password/new(.:format)  {:action=>"new", :controller=>"devise/passwords"}
      edit_user_password GET    /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
                         PUT    /users/password(.:format)      {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET    /users/cancel(.:format)        {:action=>"cancel", :controller=>"devise/registrations"}
       user_registration POST   /users(.:format)               {:action=>"create", :controller=>"devise/registrations"}
   new_user_registration GET    /users/sign_up(.:format)       {:action=>"new", :controller=>"devise/registrations"}
  edit_user_registration GET    /users/edit(.:format)          {:action=>"edit", :controller=>"devise/registrations"}
                         PUT    /users(.:format)               {:action=>"update", :controller=>"devise/registrations"}
                         DELETE /users(.:format)               {:action=>"destroy", :controller=>"devise/registrations"}
                   posts GET    /posts(.:format)               {:action=>"index", :controller=>"posts"}
                         POST   /posts(.:format)               {:action=>"create", :controller=>"posts"}
                new_post GET    /posts/new(.:format)           {:action=>"new", :controller=>"posts"}
               edit_post GET    /posts/:id/edit(.:format)      {:action=>"edit", :controller=>"posts"}
                    post GET    /posts/:id(.:format)           {:action=>"show", :controller=>"posts"}
                         PUT    /posts/:id(.:format)           {:action=>"update", :controller=>"posts"}
                         DELETE /posts/:id(.:format)           {:action=>"destroy", :controller=>"posts"}
                                /posts/:id/categ(.:format)     {:controller=>"posts", :action=>"categ"}
                                /posts/:id/tag_posts(.:format) {:controller=>"posts", :action=>"tag_posts"}
     posts_searcharchive        /posts/searcharchive(.:format) {:controller=>"posts", :action=>"searcharchive"}
              categories GET    /categories(.:format)          {:action=>"index", :controller=>"categories"}
                         POST   /categories(.:format)          {:action=>"create", :controller=>"categories"}
            new_category GET    /categories/new(.:format)      {:action=>"new", :controller=>"categories"}
           edit_category GET    /categories/:id/edit(.:format) {:action=>"edit", :controller=>"categories"}
                category GET    /categories/:id(.:format)      {:action=>"show", :controller=>"categories"}
                         PUT    /categories/:id(.:format)      {:action=>"update", :controller=>"categories"}
                         DELETE /categories/:id(.:format)      {:action=>"destroy", :controller=>"categories"}
                comments GET    /comments(.:format)            {:action=>"index", :controller=>"comments"}
                         POST   /comments(.:format)            {:action=>"create", :controller=>"comments"}
             new_comment GET    /comments/new(.:format)        {:action=>"new", :controller=>"comments"}
            edit_comment GET    /comments/:id/edit(.:format)   {:action=>"edit", :controller=>"comments"}
                 comment GET    /comments/:id(.:format)        {:action=>"show", :controller=>"comments"}
                         PUT    /comments/:id(.:format)        {:action=>"update", :controller=>"comments"}
                         DELETE /comments/:id(.:format)        {:action=>"destroy", :controller=>"comments"}
              countpages GET    /countpages(.:format)          {:action=>"index", :controller=>"countpages"}
                         POST   /countpages(.:format)          {:action=>"create", :controller=>"countpages"}
           new_countpage GET    /countpages/new(.:format)      {:action=>"new", :controller=>"countpages"}
          edit_countpage GET    /countpages/:id/edit(.:format) {:action=>"edit", :controller=>"countpages"}
               countpage GET    /countpages/:id(.:format)      {:action=>"show", :controller=>"countpages"}
                         PUT    /countpages/:id(.:format)      {:action=>"update", :controller=>"countpages"}
                         DELETE /countpages/:id(.:format)      {:action=>"destroy", :controller=>"countpages"}
                    root        /                              {:controller=>"posts", :action=>"index"}

links => 链接=>

            <% if user_signed_in? %>
                <%= link_to('Logout', destroy_user_session_path, :method => 'delete') %>                
                <%= link_to 'Add Post', :controller=>'/posts', :action=>'new' %>
                <%= link_to 'Add Category', :controller=>'/categories', :action=>'new' %>
                <%= link_to 'Display ategories', :controller=>'/categories', :action=>'index' %>
            <% else %>
                <%= link_to('Login', new_user_session_path)  %>
            <% end %>

http://0.0.0.0:3000/users/sign_out => http://0.0.0.0:3000/users/sign_out =>

Error => 错误=>

Routing Error

No route matches [GET] "/users/sign_out"

What should i do ? 我该怎么办 ?

You are calling the route using GET while the route requires DELETE, according to its definition. 根据其定义,您正在使用GET调用该路由,而该路由需要DELETE。

destroy_user_session DELETE /users/sign_out(.:format)      {:action=>"destroy", :controller=>"devise/sessions"}

The link correctly uses DELETE 链接正确使用DELETE

<%= link_to('Logout', destroy_user_session_path, :method => 'delete') %>

Did you try to visit the URL directly in your browser? 您是否尝试直接在浏览器中访问URL? In this case, it won't work. 在这种情况下,它将无法正常工作。 You need to click on a link with the DELETE method. 您需要单击带有DELETE方法的链接。

You Can try something like this This code below should works 您可以尝试这样的事情下面的代码应该工作

my best regards 我最诚挚的问候

devise_for :users, :skip => [:sessions]
as :user do
    get 'signin' => 'devise/sessions#new', :as => :new_user_session
    post 'signin' => 'devise/sessions#create', :as => :user_session
    get 'signout' => 'devise/sessions#destroy', :as => :destroy_user_session
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM