0
我試圖提交表單,但我遇到了錯誤沒有路由匹配[PATCH]
沒有路由匹配[PATCH]
我見過上的各種帖子這個錯誤,但在每一個他們只設置get
在他們的路線或一些這樣的錯誤。我也沒有問題提交幾乎相同的路由和表單結構的其他形式。
因此,首先,Security has_many :stockholders
我的表如下(地點:views/stockholders/edit.html.erb
):
<%= simple_form_for @stockholder, url: url_for{action:'update', controller:"stockholders"}, html: {id:"stockholderform"}, update: { success: "response", failure: "error"} do |f| %>
<div class="container">
<div class="symegrid">
<div class="form-inline">
<%= f.grouped_collection_select :entity_id, [Org, Person], :all, :model_name, :to_global_id, lambda {|org_or_person_object| org_or_person_object.instance_of? Org? rescue org_or_person_object.fname + " " + org_or_person_object.lname rescue org_or_person_object.name}, label:"Stockholder", class: "names"%>
</div>
<div class="form-inline">
<%= f.input :cert_number, label:"Certificate Number" %>
<%= f.input :issue_date, Label: "Issue Date" %>
</div>
</div>
<div class="submit_button">
<%= f.submit %>
</div>
</div>
<% end %>
我的控制器:
class StockholdersController < ApplicationController
def edit
@stockholder=Stockholder.find(params[:id])
@security=Security.find(params[:security_id])
@[email protected]
end
def update
@stockholder=Stockholder.find(params[:id])
@security=Security.find(params[:security_id])
@[email protected]
if @stockholder.update(stockholder_params)
redirect_to edit_security_path(@security)
else
redirect_to edit_security_stockholder_path
end
end
private
def stockholder_params
params.require(:stockholder).perimit(:id, :entity_id, :cert_number, :issue_date, :shares_issued, :shares_repurchased, :shares_canceled, :shares_outstanding)
end
end
最後,我的路線是:
resources :securities do
resources :stockholders
end
任何人都可以幫助我理解這裏發生了什麼?我以這種方式構建了兩個模型,並沒有遇到問題。
提前
非常感謝
感謝您的答覆。不幸的是我仍然遇到同樣的錯誤。 – neanderslob
明白了,只需刪除'url:{action:'update',controller:「stockholders}}'部分,並像您所說的那樣添加到@ @ security中。 – neanderslob