Reputation: 1803
I have 2 models Deal and Coupon.
Deal
has_many :couponizations, dependent: :destroy
has_many :coupons, through: :couponizations, source: :coupon
accepts_nested_attributes for :coupons
So each deal has many coupon codes, which are saved in separate table and associated via couponizations table. What I want to do is to save coupon codes attributes for deal via textarea field in Deal form (each coupon code on new line)
Form looks like this:
Deal title: || New Deal Title ||
Coupon codes:
I realize that probably I need to create virtual attribute "coupon_codes" and then split it by "\n" and save it in controller. Is there any best-practice for this?
Upvotes: 0
Views: 105
Reputation: 17949
http://railscasts.com/episodes/382-tagging
There's a good solution for array of object with nested elements like tags.
Just split the text by "\n"
Upvotes: 1