0

중첩 된 특성을 데이터베이스에 입력하려고했지만 작동하도록 관리 할 수 ​​없습니다.중첩 된 특성을 찾을 수 없거나 허용되지 않음

def domain_register_whois_contact_parameters 
    params.require(:domain).permit(whois_contacts_attributes: [:id, :first_name, :last_name, :street, :number, :postal_code, :city, :phone_number, :email_address, :company_type_id, :company_kvk, :company_name, :country_id]) 
end 

이 입력 PARAMS :이 같은

{"utf8"=>"✓", 
"authenticity_token"=>"P4WTxAHKLgeRUQq60JvD/uMjo0s2BdMtqlBr1B6Z2hQ=", 
"domain"=>{"domain_name"=>"test.com", 
"whois_contacts_attributes"=>{"0"=>{"first_name"=>"Edward", 
"last_name"=>"Doe", 
"street"=>"Broadway", 
"number"=>"1", 
"postal_code"=>"1234AB", 
"city"=>"Amsterdam", 
"country_id"=>"205", 
"phone_number"=>"316123465", 
"email_address"=>"[email protected]", 
"company_name"=>"", 
"company_kvk"=>"", 
"company_type_id"=>""}}, 
"nameserver_first"=>"ns1.dns.com", 
"nameserver_second"=>"ns2.dns.com"}, 
"commit"=>"Register domain"} 

내가지고있어 오류 : param not found: whois_contacts_attributes

은 많이 봤나요

나는이 매개 변수가 예제가 있지만 작동하지 않습니다. 내 모델에서

나는이 :

accepts_nested_attributes_for :whois_contacts 

그리고 내보기 :

나는 다르게 할 것 3 가지가 있습니다
<%= f.simple_fields_for :whois_contacts, @domain.whois_contacts.new do |wc| %> 
    <%= wc.input :first_name, input_html: { placeholder: "John" } %> 
    <%= wc.input :last_name, input_html: { placeholder: "Doe" } %> 

    <%= wc.input :street, input_html: { placeholder: "Main street" } %> 
    <%= wc.input :number, input_html: { placeholder: "1" } %> 
    <%= wc.input :postal_code, input_html: { placeholder: "1234AB" } %> 
    <%= wc.input :city, input_html: { placeholder: "Amsterdam" } %> 

    <div class="form-group select required domain_country_country_name"> 
     <label class="select required form-label" for="domain_country_country_name"> 
      <abbr title="required">*</abbr> Country 
     </label> 
     <div class="controls"> 
      <%= wc.collection_select :country_id, Country.all, :id, :full_name, {}, {:class=>'select required form-control'} %> 
     </div> 
    </div> 

    <%= wc.input :phone_number, input_html: { placeholder: "0612345678" } %> 
    <%= wc.input :email_address, input_html: { placeholder: "[email protected]" } %> 

    <h3>Company information</h3> 
    <%= wc.input :company_name, hint: 'If you have a company, please enter the company name.', input_html: { placeholder: "Doe Inc." } %> 
    <%= wc.input :company_kvk, hint: 'Enter Chamber of Commerce (Kvk) number', input_html: { placeholder: "12345678" } %> 

    <div class="form-group select required domain_company_company_name"> 
     <label class="select required form-label" for="domain_company_companyname"> 
      <abbr title="required">*</abbr> Company 
     </label> 
     <div class="controls"> 
      <%= wc.collection_select :company_type_id, CompanyType.all, :id, :full_name, {}, {:class=>'select required form-control'} %> 
     </div> 
    </div> 
<% end %> 
+0

나는거야을 형태를 조정 사지에 나가서 params를 비난하는 것. Rails 4가 옮겨온 params의 화이트리스트를 정말 좋아하지만 화이트리스트에 사용자 친화적 인 인터페이스를 만들 수있었습니다. 나는 그것에 대해 파헤 치고, 그것에 대해 질문에 대답했으며, 나는 그것이 어떻게 작동하는지 아직도 이해하지 못하고있다. 내가 여기 준 대답을 한번보세요 : http://stackoverflow.com/questions/19189602/unpermitted-parameters-for-dynamic-forms-in-rails-4/19194274#19194274 당신의 문제는 반대 생각합니다. 'permit' 문에 배열을 코딩하고 있지만, 매개 변수에 중첩 해시가 있습니다. – Beartech

+0

"whois_contacts_attributes"=> { "0"=> { "first_name"=> "Edward",''whois_contacts_attributes => { "first_name"=> "에드워드 ", ...." 이것은 내 두 번째 약점 인 simple_fields_for API를 지적합니다. 그것은 나를위한 약간의 블랙 박스입니다. 그래서 나는 그것을 빠져 나가기 원하는 매개 변수를 얻는 방법을 정말로 이해하지 못합니다. 폼에서 반환하는 매개 변수를 출력하는 폼에서 컨트롤러 동작을 수행 할 수 있습니까? 그게 내가 과거에 이들 매개 변수 신비의 일부를 사냥 한 방법이다. – Beartech

답변

2

. 같은 방법으로 호출에

1 빌드 컨트롤러에 기록

def new 
    @domain = Domain.new 
    @domain.whois_contacts.build 
end 

이 허용 된 사이트 목록

def domain_params 
    params.require(:domain).permit(:domain_name, :nameserver_first, :nameserver_second, whois_contacts_attributes: [:id, :first_name, :last_name, :street, :number, :postal_code, :city, :phone_number, :email_address, :company_type_id, :company_kvk, :company_name, :country_id])   
end 

3 더 나은 빌드 문

<%= f.simple_fields_for :whois_contacts do |wc| %> 
    <%= wc.input :first_name, input_html: { placeholder: "John" } %> 
    <%= wc.input :last_name, input_html: { placeholder: "Doe" } %> 

    <%= wc.input :street, input_html: { placeholder: "Main street" } %> 
    <%= wc.input :number, input_html: { placeholder: "1" } %> 
    <%= wc.input :postal_code, input_html: { placeholder: "1234AB" } %> 
    <%= wc.input :city, input_html: { placeholder: "Amsterdam" } %> 

    <div class="form-group select required domain_country_country_name"> 
    <label class="select required form-label" for="domain_country_country_name"> 
     <abbr title="required">*</abbr> Country 
    </label> 
    <div class="controls"> 
     <%= wc.collection_select :country_id, Country.all, :id, :full_name, {}, {:class=>'select required form-control'} %> 
    </div> 
    </div> 

    <%= wc.input :phone_number, input_html: { placeholder: "0612345678" } %> 
    <%= wc.input :email_address, input_html: { placeholder: "[email protected]" } %> 

    <h3>Company information</h3> 
    <%= wc.input :company_name, hint: 'If you have a company, please enter the company name.', input_html: { placeholder: "Doe Inc." } %> 
    <%= wc.input :company_kvk, hint: 'Enter Chamber of Commerce (Kvk) number', input_html: { placeholder: "12345678" } %> 

    <div class="form-group select required domain_company_company_name"> 
    <label class="select required form-label" for="domain_company_companyname"> 
     <abbr title="required">*</abbr> Company 
    </label> 
    <div class="controls"> 
     <%= wc.collection_select :company_type_id, CompanyType.all, :id, :full_name, {}, {:class=>'select required form-control'} %> 
    </div> 
    </div> 
<% end %> 
+0

답장을 보내 주셔서 감사합니다. 이것은 불행히도 'unknown attribute : domain_name' 오류를 발생시킵니다. – edwardmp

+0

그래서 폼과 나머지 컨트롤러의 도메인 부분을 뺀 정보가있는 더미 프로젝트를 설정하고 그 오류가 발생하지 않습니다. 차이점을 확인하고 문제를 식별 할 수 있는지 확인할 수 있습니다 (몇 가지 변경 사항이 있습니다. 실수로 company_kvm을 생략했으며 country 및 company_type은 full_name 대신 name을 사용하므로 잘라 붙이기에주의해야합니다) https : // github .com/trh/rails-nested-fieldsfor-example – trh

+0

모든 노력에 감사드립니다. 실제로 3 번 (3 가지 유형의 연락처에 대해) 빌드해야하고 이제는 성공합니다. 모든 연락처가 즉시 생성됩니다. 떠난 것은 whois_contacts에서 아직 설정되지 않은 user_id 열이 있다는 것입니다. 나는 그것을 형식의 숨겨진 필드로 만들 수 있지만 보안 관점에서 좋은 연습이되지는 않을 것입니다. 어떤 생각이야? – edwardmp