所以我有一个看起来像
的产品型号belongs_to :seller
has_many :coupons
看起来像
的优惠券模型belongs_to :seller
belongs_to :product
在我的产品控制器中,我使用
@seller = current_user
@coupon = @seller.coupons.create(params[:coupon])
为卖家创建优惠券
在创建优惠券时,我也需要将其与产品相关联,即创建新优惠券时,应该为卖家保存该产品。
答案 0 :(得分:1)
如果params[:coupon]
包含product_id
。
答案 1 :(得分:0)
您可以创建如下:
@coupon = @seller.coupons.create(params[:coupon], product_id: @product.id)