I have a problem with voteable_mongo gem when I want to validate voter id. In my app users vote for 开发者_StackOverflow社区offers and I would like to make validation for offer (only accepted users can vote). How can I do that?
In Offer model I am trying validation like this:
validates_each :votes do |record, attr, value|
ids = value["down"] + value["up"]
ids.each do |id|
record.errors.add attr, "you can`t vote" if not User.find(id).can_vote?(record)
end
end
but it doesn't work. Any suggestions?
精彩评论