开发者

Validate voter id in rails3 + mongoid + voteable_mongo

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?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜