【发布时间】:2018-12-18 12:31:46
【问题描述】:
我有三个模型,即“Employee::TaxSettingBatch”、“Employee::HousingLoanInterest”、“Employee::InvestmentBankDetail”。这些模型相互关联如下
class Employee::TaxSettingBatch
include Mongoid::Document
has_one :housing_loan_interest, class_name: Employee::HousingLoanInterest'
accepts_nested_attributes_for :housing_loan_interest, allow_destroy: true
end
class Employee::HousingLoanInterest
include Mongoid::Document
field :property_type, type: String
belongs_to :employee_tax_setting_batch, class_name: 'Employee::TaxSettingBatch'
has_many :investment_bank_details, class_name: 'Employee::InvestmentBankDetail'
accepts_nested_attributes_for :investment_bank_details, allow_destroy: true
end
问题是,当我尝试保存数据时,我遇到了错误。
问题: 尝试为 Employee::TaxSettingBatch 模型设置不允许的“employee_housing_loan_interest”值。
我的参数是:
{"utf8"=>"✓",
"_method"=>"patch",
"authenticity_token"=>"Afig1spGvAgNX9bj7VEwRLO6FvTVH+ZOtNDBpEHY+LF4c10yn0KUHAlOn5oB/isfOwQF/VHjIcT7Etm2t0MHfA==",
"section"=>"housing_loan_info",
"employee_tax_setting_batch"=>
{"employee_housing_loan_interest"=>
{"property_type"=>"Self occupied property",
"_destroy"=>"false",
"investment_bank_details_attributes"=>
{"1545132357997"=>
{"loan_type"=>"Self",
"construction_completion_month_and_year"=>"jan 200",
"lender_bank_name"=>"hdfc",
"lender_pan_number"=>"bcopp15",
"loan_interest_details_attributes"=>
{"0"=>{"component"=>"Pre EMI Amount", "declared_amount"=>"2", "verified_amount"=>"3", "remarks"=>""},
"1"=>{"component"=>"Interest Repayment amount", "declared_amount"=>"2", "verified_amount"=>"3", "remarks"=>""}}}}}},
"disallowed_amount"=>"",
"controller"=>"employee/tax_setting_batches",
"action"=>"update",
"company_id"=>"55532e18517569120b7b0000",
"employee_id"=>"55532e18517569120b7c0000",
"tax_setting_id"=>"5bfe84d8c142e30aa0000125",
"id"=>"5c0f9676c142e309980002cb"}
“employee_housing_loan_interest”的参数没有作为“employee_housing_loan_interest_attributes”发送,这就是我遇到此问题的原因。帮帮我!
我的表格:
<%= nested_form_for @tax_setting_batch, url: company_employee_tax_setting_tax_setting_batch_path(@company, @employee, @tax_setting, @tax_setting_batch), html: {id: 'form-80c-details', class: 'form-horizontal'}, remote:true,:authenticity_token=> true do |f| %>
<%= f.fields_for @tax_setting_batch.housing_loan_interest.nil? ? @tax_setting_batch.build_housing_loan_interest : @tax_setting_batch.housing_loan_interest , :wrapper => false do |form| %>
【问题讨论】:
标签: ruby-on-rails nested-forms