중첩 된 필드의 내용을 저장하는 데 문제가 있습니다. 두 모델은 Incorporation
및 Company
입니다.오류 : 중첩 된 특성이있는 허용되지 않은 매개 변수
class Company < ActiveRecord::Base
belongs_to :incorporation
end
class Incorporation < ActiveRecord::Base
has_one :company
accepts_nested_attributes_for :company
end
는가 포함 과정의 컨트롤러와 뷰를 모두 사용하여, 동일한 형태의 새로운 Company
및 Incorporation
항목을 만드는 것입니다 목표로 내 다음과 같이 그들은 관련이있다.
(문제가) 그러나 때마다 내가 양식을 제출하려고, 합동 항목은 통과하지만 회사의 항목은 Unpermitted parameters
오류와 함께 개최된다
Started POST "/incorporations" for 127.0.0.1 at 2014-12-15 22:40:59 -0700
Processing by IncorporationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"lCj/ZtNNE/9l/UAlYcnA8EAe8vmMN010toS4t5e+ZkA=", "incorporation"=>{"title"=>"test", "company"=>{"name"=>"test"}}, "button"=>""}
Unpermitted parameters: company
Completed 500 Internal Server Error in 4ms
이 내가로서 특히 놀라운 일이다 beleive 나는 강한 params을 올바르게 설정했습니다. 아래 내 컨트롤러입니다.
<%= form_for @incorporation do |f| %>
<div class="panel-body">
<%= f.text_field :title, input_html: { class: 'form-control' } %>
<h3>TEST</h3>
<%= f.fields_for @company do |company| %>
<%= company.text_field :name, input_html: { class: 'form-control' } %>
<% end =%>
</div>
<%= f.button :submit, class: "btn btn-primary" %>
<% end =%>
모든 아이디어를 주시면 감사하겠습니다 다음과 같이
class IncorporationsController < ApplicationController
def index
end
def show
end
def new
@incorporation = Incorporation.new
@company = Company.new
end
def create
@incorporation = Incorporation.new(incorporation_params)
if @incorporation.save
redirect_to @incorporation, notice: "Successfuly saved incorporation info."
else
render 'new'
end
end
def edit
end
def show
end
private
def incorporation_params
params.require(:incorporation).permit(:title, company_attributes: [:name, :state_corp, :street, :city, :state, :zip, :outstanding_common_stock, :fiscal_year_end_month, :fiscal_year_end_day])
end
end
내가 사용 부분 양식입니다.
: 회사가 아닌 '@ 회사'AND'@ 회사 '='@ 조합. 빌드 업체 \' – argentum47
@ argentum47 안녕하세요, 고마워요! 귀하의 의견을 답변으로 적어두면 신용을 줄 수 있습니다. – neanderslob