【发布时间】:2018-04-25 02:13:50
【问题描述】:
型号
prd_item.rb
has_many :prd_allisland_flat_deliveries, 依赖: :destroy, inverse_of: :prd_item
prd_allisland_flat_delivery.rb
belongs_to :prd_item
在主窗体中
<%= p.fields_for :prd_allisland_flat_deliveries do |i| %>
<%= render(:partial => 'prd_allisland_flat_delivery_field', :locals => {:f => i})%>
<% end %>
在 prd_allisland_flat_delivery_field 表单部分
<div class="row" style="padding-bottom: 25px">
<div class="col-md-2"></div>
<div class="col-md-4">
<%= f.label :delivery_period %>
</div>
<div class="col-md-4">
<%= f.text_field(:delivery_period, {placeholder: '0', class: 'form-control input_border input_field_text_align_right'})%>
</div>
<div class="col-md-2"></div>
</div>
<div class="row" style="padding-bottom: 25px">
<div class="col-md-2"></div>
<div class="col-md-4">
<%= f.label :delivery_rate %>
</div>
<div class="col-md-4">
<%= f.text_field(:delivery_rate, {placeholder: 'Rs. 0.00', class: 'form-control input_border input_field_text_align_right'})%>
</div>
</div>
在prd_item控制器中
**定义新
@item = PrdItem.new
@item.prd_allisland_flat_deliveries.build
结束**
写完这个创建方法
**
if @item.save
if @item.delivery_type == 1
@all_island_flat = @item.prd_allisland_flat_deliveries.build(item_params[:prd_allisland_flat_deliveries_attributes])
@all_island_flat.save
end
结束**
item_params
定义项目参数
params.require(:prd_item).permit(:item_name, :brand, :item_no, :short_description, :long_description, :prd_type_id, :usr_vendor_property_id, :price,:base_price, :price_discount, :percentage_discount, :stock_count, :availability, :tags, :remove_image, :delivery_type , :min_stock_count,
prd_item_images_attributes: [:id, :image, :description, :link, :_destroy ],
prd_temp_variation_stores_attributes: [:id, :product_variations, :variation_items, :_destroy],
prd_temp_compound_stores_attributes:[:id,:compound, :compound_item, :_destroy],
prd_temp_spec_stores_attributes:[:id,:compound, :compound_item, :_destroy],
prd_allisland_flat_deliveries_attributes: [:id,:delivery_period,:delivery_rate],
prd_province_vise_deliveries_attributes: [:id , :province_name , :delivery_rate, :delivery_period]
)
结束
rails 控制台获取 Unpermitted 参数:prd_allisland_flat_deliveries
谁能解释原因
如果图片不清晰
参数:{"utf8"=>"✓", "authenticity_token"=>"ZqJOX4nMmWyVG2CxJznKKxLLsUkG+4ndBFdvxfx2TPouiQkIbYfvQ00moCdqFZWPd0nJ4ipCVY9JhVToESDCoQ==", "prd_item"=>{"item_name"=>"666", ", "品牌"=>"" , "prd_type_id"=>"", "short_description"=>"", "long_description"=>"", "tags"=>"", "prd_item_images_attributes"=>{"0"=>{"_destroy"=> "false", "description"=>"", "link"=>""}}, "base_price"=>"655", "price"=>"688 ", "price_discount"=>"5", "prd_temp_spec_stores_attributes"=>{"0"=>{"spec_item"=>"", "spec"=>""}}, "prd_temp_variation_stores_attributes"=>{"0" =>{"product_variations"=>"", "variation_items"=>""}}, "prd_temp_ Compound_stores_attributes"=>{"0"=>{"compound_item"=>"", "compound"=>""}}, "stock_count"=>"55", "min_stock_count"=>"5", "可用性" =>“可用”,“delivery_type”=>“1”,“prd_allisland_flat_deliveries”=>{“d elivery_period"=>"255", "delivery_rate"=>"22"}, "prd_province_vise_deliveries"=>{"delivery_rate"=>"", "delivery_period"=>""}}, "commit"=>"添加产品"}
不允许的参数:prd_allisland_flat_deliveries、prd_province_vise_deliveries
SQL (1.0ms) INSERT INTO "prd_allisland_flat_deliveries" ("prd_item_id", "created_at", "updated_at") 值 ($1, $2, $3) 返回 "id" [["prd_item_id", 52], ["created_at ", 2017-11-12 14:02:09 UTC], ["更新 ated_at", 2017-11-12 14:02:09 UTC]]
【问题讨论】:
-
你能在浏览器上显示完整的表单吗
-
查看新版问题
-
对不起,我的意思是表单的视图源
-
你的意思是代码片段
-
是的。我想看看表单的代码有什么
标签: ruby-on-rails