我正在使用CentOS 5.6
rails 3.2.13
和ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-linux]
。當我嘗試播種數據時,出現以下錯誤。的ActiveRecord :: RecordNotSaved - Rails 3個的播種數據
** 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)>'
record_status.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
你有什麼樣的模型驗證對RECORDSTATUS模型? – apotry
@ peri08我更新了我的問題 – Bathakarai