2011-04-14 92 views
1

然而,当运行耙:航线它似乎是有:Rails的RoutingError:没有路由匹配{:控制器=> “会话”,:动作=> “消灭”}

 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' 

回答

9

这有可能是你没有通过:ID PARAM在你的路线,这就是为什么该路由不匹配,因为:ID要求:

session DELETE /sessions/:id(.:format) {:action=>"destroy", :controller=>"sessions"} 

注:各地括号:格式PARAM意味着它是可选。

2

这看起来像是我在运行http://ruby.railstutorial.org/时遇到的一个错误,事实证明我在routes.rb中留下了一些内容。资源路线的加入是伴随着以下两个附加路线:

match '/signin', :to => 'sessions#new' 
match '/signout', :to => 'sessions#destroy' 

很难看到,因为该组中的第一条路线已经存在,所以我刚刚掩饰组(多次)作为已经在那里。

+0

_Why_是否添加此修复路线?这不是关于URL。如果我将URL更改为/ signoutXXX,它仍然会成功。显然这是关于动作的,因为如果我将其更改为#destroyXXX,它将失败。事实上_something_将会'会议#破坏'似乎会造成所有差异,所以为什么没有简单的'resources:sessions'来完成这项工作? – 2011-12-13 13:51:00

-1

resources controller增加了地图的方法

{:action=>"method", :controller=>"controller"}

当你的情况铁轨似乎要求明确将地图作为

{:controller=>“controller”, :action=>“method”}

:controller:action

前这也回答了Noach的问题是,为什么match '/signout', :to => 'sessions#destroy'有存在,如果你耙:路线你会看到它添加

{:controller=>“sessions”, :action=>“destroy”}虽然已经有一个 {:action=>“destroy”, :controller=>“sessions”}通过resources sessions

+0

ruby​​ hashsmaps没有排序。 – 2017-09-20 11:00:23

8

加入我得到了相同的错误well.But的原因是小错误,在我看到的页面我写 <%= form_for(:session,url:session_path) do |f| %> 哪个我最后'的'会议'。

相关问题