0
私のparams好き、私は1つのExcelファイルをインポートすることにより、3つのテーブル内のデータを保存したいネストされた属性は、レール4
params.require(:subject).permit(:id, :org_id, :subject_id, :subject_name, :subject_desc,
:subject_color, subject_modules_attributes: [:id, :subject_module_id, :subject_id,
:module_number, :module_name, :_destroy,
module_details_attributes: [:id, :module_detail_id, :subject_module_id,
:module_detail_number, :description, :_destroy]])
でインポートを優れています。それはカンガルーの宝石に
def self.import(file)
allowed_attributes = ["org_id", "subject_name", "subject_desc","subject_color",
subject_modules_attributes: ["org_id", "standard_id", "subject_id", "module_number", "module_name"],
module_details_attributes: ["subject_module_id", "module_detail_number", "description"]]
Spreadsheet.client_encoding = 'UTF-8'
spreadsheet = open_spreadsheet(file)
header = spreadsheet.row(1)
(2..spreadsheet.last_row).each do |i|
row = Hash[[header, spreadsheet.row(i)].transpose]
subject = new
subject.attributes = row.to_hash.slice(*allowed_attributes)
subject.save!
end
end
を使用して可能であるどのように私は、データテーブルを最初に保存されますが、ネストされたパラメータにsubject_modulesとmodule_detailsとして2番目と3番目のテーブルを保存することができませんでした。どのように私は、