lundi 24 mars 2014

Trouble writing action


Vote count:

0




I have an action in my Miniatures model called set_gold_and_silver.


I want my Users model to run it when a User is destroyed, so I have before_destroy :set_gold_and_silver in my User model.


A User has many Collections. A Collection belongs to a Miniature. A User may have multiple Collections with the same Miniature. I want to run the set_gold_and_silver action on every unique User.collection.miniature


As part of an answer to another question I got the following code



def set_gold_and_silver
self.collection.map(&:miniature).uniq.each(&:set_gold_and_silver)
end


But with testing it doesn't appear to be running the action as hoped.



asked 46 secs ago






Aucun commentaire:

Enregistrer un commentaire