Rails saving data to model that has multiple has_many
Posted
by
Ajey
on Stack Overflow
See other posts from Stack Overflow
or by Ajey
Published on 2013-10-22T09:48:17Z
Indexed on
2013/10/22
9:54 UTC
Read the original article
Hit count: 164
ruby-on-rails
|activerecord
So I have a product model that looks like
belongs_to :seller
has_many :coupons
And coupon model that looks like
belongs_to :seller
belongs_to :product
And in my Products controller I use
@seller = current_user
@coupon = @seller.coupons.create(params[:coupon])
to create the coupons for the seller
While the coupon is being created, I need to associate it with the product too, i.e When a new coupon is created it should be saved for the seller AS WELL AS for the product.
© Stack Overflow or respective owner