2014-10-08 87 views
0

提交表單時,我收到以下錯誤時:沒有路由匹配[PATCH]使用polymorphic_path

No route matches [PATCH] "/foreclosure_defenses/4/properties" 

即使在瀏覽器的HTML看起來像這樣:

<form accept-charset="UTF-8" action="/foreclosure_defenses/4/properties" class="form-horizontal" id="edit_foreclosure_defense_4" method="post"> 

由於新形式呈現多態模型和屬性模型,我創建我的形式如下:

<%= form_for @owner, url: polymorphic_path([@owner, @property]) do |f| %> 
    <%= f.fields_for :properties, @property do |property_builder| %> 
    <%= render 'form', f: property_builder %> 
    <% end %> 
<% end %> 

爲什麼我得到這個補丁錯誤?表單是用POST提交的,應該去CREATE方法。

下面是相關航線:

foreclosure_defense_properties_path GET /foreclosure_defenses/:foreclosure_defense_id/properties(.:format) properties#index 

POST /foreclosure_defenses/:foreclosure_defense_id/properties(.:format) properties#create 

new_foreclosure_defense_property_path GET /foreclosure_defenses/:foreclosure_defense_id/properties/new(.:format) properties#new 

edit_foreclosure_defense_property_path GET /foreclosure_defenses/:foreclosure_defense_id/properties/:id/edit(.:format) properties#edit 

foreclosure_defense_property_path GET /foreclosure_defenses/:foreclosure_defense_id/properties/:id(.:format) properties#show 

PATCH /foreclosure_defenses/:foreclosure_defense_id/properties/:id(.:format) properties#update 

PUT /foreclosure_defenses/:foreclosure_defense_id/properties/:id(.:format) properties#update 

DELETE /foreclosure_defenses/:foreclosure_defense_id/properties/:id(.:format) properties#destroy 

回答

0

該結束了工作被明確定義的HTTP方法解決辦法:

<%= form_for @owner, url: polymorphic_path([@owner, @property]), method: :post, html: {class: "form-horizontal"} do |f| %> 

不知道爲什麼,這是必需的。 Poymorphic路徑應該足夠聰明,以確定這是我認爲的創建行爲。