开发者

Using Callback or Observer to add attributes to associated model

开发者 https://www.devze.com 2023-02-12 05:32 出处:网络
I would like after saving in one model to create a few lists in开发者_运维百科 my list model. So I can get that to work for one list in the controller (I know bad) like this:

I would like after saving in one model to create a few lists in开发者_运维百科 my list model.

So I can get that to work for one list in the controller (I know bad) like this:

     @move.save
     @list = List.new(:name => 'This is a List', :move_id => @move.id)
     @list.save

I need to move that to the model or an observer and then be able to add several different lists with that one action. I am not sure how to do this. Any help? Thanks.


This should be in an observer, as I believe a callback should only make changes to the object it is a part of, whereas an observer can interact with other models.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号