参数在控制台中但不传递给数据库
在主要forms
'prd_allisland_flat_delivery_field', :locals => {:f => i})%>
在prd_allisland_flat_delivery_field表单中
在prd_item控制器中
** def new
@item = PrdItem.new @item.build_prd_allisland_flat_delivery
结束**
在写完这个create方法之后
**
if @item.save if @item.delivery_type == 1 @all_island_flat = PrdAllislandFlatDelivery.new(item_params[:prd_allisland_flat_deliveries_attributes]) @all_island_flat.save end
结束**
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] )
结束
rails consoler获取prd_allisland_flat_deliveries的属性,但prd_all_island_flat_deliveries填充空值
这是你的完整创建方法吗? 如果是这样,您需要了解每个请求都与其他请求分开,创建请求不知道新请求中发生了什么。
在您的create方法中,您需要构建基本对象,然后从params更新对象。
def create @item = PrdItem.new @item.update(item_params) if @item.save ...