1
昨天我有這個工作,我不知道我做了什麼來打破它。Rails 3路由錯誤
這裏是一個RESTful控制器路線:
brand_responsibilities GET /brands/:brand_id/responsibilities(.:format) {:action=>"index", :controller=>"responsibilities"}
brand_responsibilities POST /brands/:brand_id/responsibilities(.:format) {:action=>"create", :controller=>"responsibilities"}
new_brand_responsibility GET /brands/:brand_id/responsibilities/new(.:format) {:action=>"new", :controller=>"responsibilities"}
edit_brand_responsibility GET /brands/:brand_id/responsibilities/:id/edit(.:format) {:action=>"edit", :controller=>"responsibilities"}
brand_responsibility GET /brands/:brand_id/responsibilities/:id(.:format) {:action=>"show", :controller=>"responsibilities"}
brand_responsibility PUT /brands/:brand_id/responsibilities/:id(.:format) {:action=>"update", :controller=>"responsibilities"}
brand_responsibility DELETE /brands/:brand_id/responsibilities/:id(.:format) {:action=>"destroy", :controller=>"responsibilities"}
我的形式如下:
<%= form_for :responsibility, :remote => true do |f| %>
<%= f.hidden_field :access_request_id, :value => ar.id %>
<%= f.hidden_field :user_id, :value => user.id %>
<%= f.hidden_field :brand_id, :value => @brand.id %>
<%= f.submit %>
<% end %>
但我得到一個404現在有了這個日誌消息:
Started POST "/brands/30/responsibilities" for 127.0.0.1 at Tue Oct 26 10:47:17 -0400 2010
ActionController::RoutingError (No route matches "/brands/30/responsibilities"):
它確實看起來像路線匹配我!我錯過了什麼?
更新:我也是在控制檯中嘗試這樣的:
rs.recognize_path '/brands/30/responsibilities', :method => :post
和反應是:
=> {:controller=>"responsibilities", :brand_id=>"30", :action=>"create"}
什麼是我的交易?
更新#2:
我找到了原因,但我不知道爲什麼它的原因做。我有另一個字段:
<%= button_to "Deny", brand_responsibilities_path(@brand, :ar => ar), :remote => true, :method => :delete %>
那我在表單中包括。爲了簡潔起見,我之前沒有看到它,因爲我認爲它不重要。我看到這是一個糟糕的主意。
有沒有人知道爲什麼表單中該行的存在會導致奇怪的路由錯誤?
奇怪!隨着你提供的信息,它應該工作。將路由添加到'config/routes.rb'之後,你重新啓動了服務器嗎? – Ariejan 2010-10-26 15:14:35
這可能不會幫助您解決問題,但只需知道......您可以使用<%form_for [@brand,:responsibility]來避免隱藏字段傳遞品牌ID。這也會在表單中生成/ brands /:id/responsibilities動作。除此之外,對於您的問題的唯一解釋是,優先級較高(路由列表較低)的路線會覆蓋您粘貼的路線。 – jenjenut233 2010-10-26 16:58:19
是的,我已經重新啓動,一切。我將這個表單重新配置爲你的例子Jen,而我在Bates的Controller in Rails 3 screencast中也看到了這一點。仍然是同樣的事情。我的路線是: 資源:品牌做 資源:責任 結束 沒有什麼一般是高於或低於它在routes.rb中。 – AKWF 2010-10-26 17:50:49