我有一个模型的Mysql ::错误:重复的项目
class Gift < ActiveRecord::Base
validates_uniqueness_of :giver_id, :scope => :account_id
end
add_index(:gifts, [:account_id, :giver_id], :uniq => true)
行动
def create
@gift= Gift.new(params[:gift])
if @gift.save
...
else
...
end
end
在 “生产” 的模式,我有时会得到一个错误
ActiveRecord::StatementInvalid: Mysql::Error: Duplicate entry '122394471958-50301499' for key 'index_gifts_on_account_id_and_user_id'
什么问题?
在你的例子中什么是params [:gift]值? – shingara 2010-04-09 07:22:42
{:ACCOUNT_ID => “122394471958”,:giver_id => “50301499”} – Shaliko 2010-04-09 07:50:12