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