【发布时间】:2011-10-17 13:09:06
【问题描述】:
我有以下设置:
class Vote < ActiveRecord::Base
belongs_to :voteable, :polymorphic => :true, :counter_cache => true
end
class Proposition < ActiveRecord::Base
has_many :votes, :as => :voteable
end
class Winner < ActiveRecord::Base
has_many :votes, :as => :voteable
end
投票表如下所示:
t.string "ip_address"
t.integer "voteable_id"
t.string "voteable_type"
我想验证以下内容。具有给定 ip_address 的用户只能对 1 个提议进行投票。所以ip_address、voteable_id和voteable_type的组合需要是唯一的。
如何使用“简单”的验证规则来实现这一点?
【问题讨论】:
标签: ruby-on-rails-3 validation unique