How to update a model's attribute with a virtual attribute?

前端 未结 2 1770
说谎
说谎 2021-01-15 15:27

I have a model named UserPrice which has the attribute :purchase_date(a date_select) in its table. With my form I can create multiple user_prices a

2条回答
  •  无人共我
    2021-01-15 16:24

    I'm not sure why you are even using that virtual attribute is there more to this implementation? If you are just trying to save an associated model, you might simply want a accepts_nested_attributes_for :user_prices in your User model

    This works great and many developers use this method, so it's nice to know for working on other projects as well as for the people who might end up maintaining yours.

    http://railscasts.com/episodes/196-nested-model-form-part-1

    http://railscasts.com/episodes/197-nested-model-form-part-2

提交回复
热议问题