我是Ruby on Rails + angularJS的新手,尝试将数据插入多个级别(嵌套)表格,这里是我的控制器代码,(模型关系:Wines有奖项,广告系列和广告系列促销活动)
params.fetch(:wine).permit(:wine_name, :terroir, :vintage, :bottle_size, :size_unit, :description,
:campaigns_attributes => [:id, :campaign_name, :start_date, :end_date, :quantity, :campaign_price, :regular_price, :status, :created_date, :wines_id,
:promotions_attributes => [:id, :campaign_id, :discount_value, :discount_type, :discount_off, :quantity, :quantity_unit]],
:awards_attributes => [:id, :wines_id, :title, :description, :award_date, :image])
收到错误“8ms内完成500内部服务器错误(ActiveRecord: 0.0ms
)”
Processing by Admin::Api::WinesController# create as JSON
Parameters: {
"wine" => {
"wine_name" => "Name",
"terroir" => "Terroir",
"vintage" => "2010",
"bottle_size" => "12",
"size_unit" => "ml",
"description" => "EDesc",
"award" => {
"title" => "Title",
"description" => "Desc",
"award_date" => "2016-11-01"
},
"campaign" => {
"start_date" => "2016-11-01",
"end_date" => "2016-11-25",
"quantity" => "12",
"campaign_price" => "12",
"regular_price" => "12",
"status" => 0,
"created_date" => ""
},
"promotions" => [{
"discount_value" => "1", "discount_type" => "%", "discount_off" => "Off Subtotal", "quantity" => "1", "quantity_unit" => "bottle"
}, {
"discount_value" => "2", "discount_type" => "%", "discount_off" => "Off Subtotal", "quantity" => "2", "quantity_unit" => "bottles"
}]
}
}
在rails控制台中,数据显示如上,但是我误以为“ TypeError(没有将符号隐式转换为整数):”
我正在做什么错误,控制器部分也是正确的,可以将数据插入到嵌套表中吗?