开发者

Using Callback or Observer to add attributes to associated model

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜