自定义路线没有路线匹配

时间:2011-08-30 03:35:20

标签: ruby-on-rails ruby-on-rails-3 routes cucumber

在黄瓜测试期间,我收到以下错误:

No route matches "/companies/29/update_owner"

我不确定我做错了什么,但我确定它有点蠢。

我有以下路线:

company_update_owner POST   /companies/:company_id/update_owner(.:format) {:controller=>"companies", :action=>"update_owner"}
company_set_owner        /companies/:company_id/set_owner(.:format)    {:controller=>"companies", :action=>"set_owner"}
       companies GET    /companies(.:format)                          {:action=>"index", :controller=>"companies"}
                 POST   /companies(.:format)                          {:action=>"create", :controller=>"companies"}
     new_company GET    /companies/new(.:format)                      {:action=>"new", :controller=>"companies"}
    edit_company GET    /companies/:id/edit(.:format)                 {:action=>"edit", :controller=>"companies"}
         company GET    /companies/:id(.:format)                      {:action=>"show", :controller=>"companies"}
                 PUT    /companies/:id(.:format)                      {:action=>"update", :controller=>"companies"}
                 DELETE /companies/:id(.:format)                      {:action=>"destroy", :controller=>"companies"}

我试过了:

company_update_owner_path(:company_id => @company.id)

company_update_owner_path(@company)

更新

= form_for @company, :url => company_update_owner_path(:company_id => @company.id), :method => :put do |f|

非常感谢任何帮助。

以下是routes.rb中的代码:

resources :companies do
    match '/update_owner' => 'companies#update_owner', :as => :update_owner, :via => :post
    match '/set_owner' => 'companies#set_owner', :as => :set_owner
end

3 个答案:

答案 0 :(得分:1)

您的路线被声明为POST,但您在表格中正在进行PUT。修复路线或表格,你会指出它。

答案 1 :(得分:1)

您需要删除“:method =>:put”

答案 2 :(得分:0)

会留下这个评论,但是这个问题会得到解决。 如果你不知道,你也可以稍微不同地定义这些路线:

resources :companies do
  member do
    post "update_owner"
    get "set_owner"
  end
end