Models
prd_item.rb
has_many :prd_allisland_flat_deliveries, dependent: :destroy, inverse_of: :prd_item
prd_allisland_flat_delivery.rb
belongs_to :prd_item
in Main form
<%= p.fields_for :prd_allisland_flat_deliveries do |i| %>
<%= render(:partial => 'prd_allisland_flat_delivery_field', :locals => {:f => i})%>
<% end %>
in the prd_allisland_flat_delivery_field form partial
<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>
in prd_item controller
**def new
@item = PrdItem.new
@item.prd_allisland_flat_deliveries.build
end**
after writing this the create method
**
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
end**
the item_params
def 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]
)
end
the rails consoler gets the Unpermitted parameters: prd_allisland_flat_deliveries
can anyone explain why
in case the pictures are not clear
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ZqJOX4nMmWyVG2CxJznKKxLLsUkG+4ndBFdvxfx2TPouiQkIbYfvQ00moCdqFZWPd0nJ4ipCVY9JhVToESDCoQ==", "prd_item"=>{"item_name"=>"abc", "item_no"=>"666333", "brand"=>"" , "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", "availability"=>"available", "delivery_type"=>"1", "prd_allisland_flat_deliveries"=>{"d elivery_period"=>"255", "delivery_rate"=>"22"}, "prd_province_vise_deliveries"=>{"delivery_rate"=>"", "delivery_period"=>""}}, "commit"=>"ADD PRODUCT"}
Unpermitted parameters: prd_allisland_flat_deliveries, prd_province_vise_deliveries
SQL (1.0ms) INSERT INTO "prd_allisland_flat_deliveries" ("prd_item_id", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["prd_item_id", 52], ["created_at", 2017-11-12 14:02:09 UTC], ["upd ated_at", 2017-11-12 14:02:09 UTC]]