我正在使用rails 3.2.13
和ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-linux]
在CentOS 5.6
. 当我尝试播种数据时,出现以下错误。
** Execute Samp:seed:record_status
Creating RecordStatus: Active
rake aborted!
ActiveRecord::RecordNotSaved
/usr/local/rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/persistence.rb:105:in `save!'
/usr/local/rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/validations.rb:56:in `save!'
/usr/local/rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/attribute_methods/dirty.rb:33:in `save!'
/usr/local/rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.13/lib/active_record/transactions.rb:264:in `block in save!'
/opt/Samp/lib/tasks/seed/record_status.rake:19:in `block (4 levels) in <top (required)>'
/opt/Samp/lib/tasks/seed/record_status.rake:16:in `each'
/opt/Samp/lib/tasks/seed/record_status.rake:16:in `block (3 levels) in <top (required)>'
记录状态.rake
16: record_statuses.each do |rs|
17: unless RecordStatus.find_by_seed_name(rs[:name])
18: puts "Creating RecordStatus: #{rs[:name]}"
19: RecordStatus.create!(:name => rs[:name],
20: :seed_name => rs[:name],
21: :description => rs[:description])
22: end
23: end
EDIT-1 * RecordStatus.rb *
class RecordStatus < ActiveRecord::Base
acts_as_enumerated
ACTIVE = 1
DISABLED = 2
DELETED = 3
validates_uniqueness_of :id , :name
end