Rails RoutingError:没有路由匹配{:controller =>"sessions",:action =>"destroy"}

Two*_*ter 1 routing ruby-on-rails-3

然而,当运行rake:路线似乎在那里:

     users GET    /users(.:format)          {:action=>"index", :controller=>"users"}
            POST   /users(.:format)          {:action=>"create", :controller=>"users"}
   new_user GET    /users/new(.:format)      {:action=>"new", :controller=>"users"}
  edit_user GET    /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
       user GET    /users/:id(.:format)      {:action=>"show", :controller=>"users"}
            PUT    /users/:id(.:format)      {:action=>"update", :controller=>"users"}
            DELETE /users/:id(.:format)      {:action=>"destroy", :controller=>"users"}
   sessions POST   /sessions(.:format)       {:action=>"create", :controller=>"sessions"}
new_session GET    /sessions/new(.:format)   {:action=>"new", :controller=>"sessions"}
    session DELETE /sessions/:id(.:format)   {:action=>"destroy", :controller=>"sessions"}
     signup        /signup(.:format)         {:controller=>"users", :action=>"new"}
    contact        /contact(.:format)        {:controller=>"pages", :action=>"contact"}
      about        /about(.:format)          {:controller=>"pages", :action=>"about"}
       help        /help(.:format)           {:controller=>"pages", :action=>"help"}
       root        /(.:format)               {:controller=>"pages", :action=>"home"}

Here are the routes from routes.rb:

  resources :users
  resources :sessions, :only => [:new, :create, :destroy]


  match '/signup', to: 'users#new'
  match '/contact', to: 'pages#contact'
  match '/about', to: 'pages#about'
  match '/help', to: 'pages#help'
Run Code Online (Sandbox Code Playgroud)

Sco*_*ott 10

您可能没有在路由中传递:id param,这就是路由不匹配的原因,因为:id是必需的:

session DELETE /sessions/:id(.:format)   {:action=>"destroy", :controller=>"sessions"}
Run Code Online (Sandbox Code Playgroud)

注意:格式参数周围的括号表示它是可选的.


xgu*_*uox 8

我也得到了同样的错误.但原因是在我写的视图页面中的一个小错误, <%= form_for(:session,url:session_path) do |f| %> 我不再是'会话'的最后一个'.