运行我的 rake 任务时收到以下错误:
Validation failed: Account can't be blank
这是引发错误的代码位:
test.entries.create!({
:account_id => account.id,
:date => date
})
我对两者的验证test
仅entries
验证:account_id
. 我知道错误信息是人性化的删除.id
,但很明显:account_id
存在。我在这里想念什么?我正在使用导轨 3.1.14。
编辑:
完整的跟踪错误如下 -
rake aborted!
Validation failed: Account can't be blank
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/validations.rb:56:in `save!'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/attribute_methods/dirty.rb:33:in `save!'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/transactions.rb:264:in `block in save!'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/transactions.rb:208:in `transaction'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/transactions.rb:264:in `save!'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/associations/has_many_through_association.rb:85:in `save_through_record'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/associations/has_many_through_association.rb:52:in `insert_record'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/autosave_association.rb:348:in `block in save_collection_association'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/autosave_association.rb:341:in `each'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/autosave_association.rb:341:in `save_collection_association'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/autosave_association.rb:191:in `block in add_autosave_association_callbacks'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/autosave_association.rb:161:in `instance_eval'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/autosave_association.rb:161:in `block in define_non_cyclic_method'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activesupport-3.2.14/lib/active_support/callbacks.rb:413:in `_run__3251750978270077373__create__1709181034843668520__callbacks'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activesupport-3.2.14/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activesupport-3.2.14/lib/active_support/callbacks.rb:385:in `_run_create_callbacks'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activesupport-3.2.14/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/callbacks.rb:268:in `create'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/persistence.rb:348:in `create_or_update'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/callbacks.rb:264:in `block in create_or_update'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activesupport-3.2.14/lib/active_support/callbacks.rb:447:in `_run__3251750978270077373__save__1709181034843668520__callbacks'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activesupport-3.2.14/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activesupport-3.2.14/lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activesupport-3.2.14/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/callbacks.rb:264:in `create_or_update'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/persistence.rb:104:in `save!'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/validations.rb:56:in `save!'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/attribute_methods/dirty.rb:33:in `save!'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/transactions.rb:264:in `block in save!'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/transactions.rb:208:in `transaction'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/transactions.rb:264:in `save!'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/associations/has_many_association.rb:14:in `insert_record'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/associations/collection_association.rb:436:in `block (2 levels) in create_record'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/associations/collection_association.rb:344:in `add_to_target'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/associations/collection_association.rb:434:in `block in create_record'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/associations/collection_association.rb:149:in `block in transaction'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/transactions.rb:208:in `transaction'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/associations/collection_association.rb:148:in `transaction'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/associations/collection_association.rb:433:in `create_record'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/associations/collection_association.rb:123:in `create!'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/activerecord-3.2.14/lib/active_record/associations/collection_proxy.rb:46:in `create!'
/Users/Luigi/Desktop/Projects/test/lib/tasks/createnew.rake:179:in `block (5 levels) in <top (required)>'
/Users/Luigi/Desktop/Projects/test/lib/tasks/createnew.rake:165:in `each'
/Users/Luigi/Desktop/Projects/test/lib/tasks/createnew.rake:165:in `block (4 levels) in <top (required)>'
/Users/Luigi/Desktop/Projects/test/lib/tasks/createnew.rake:90:in `upto'
/Users/Luigi/Desktop/Projects/test/lib/tasks/createnew.rake:90:in `block (3 levels) in <top (required)>'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/Luigi/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/Luigi/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/bin/rake:19:in `load'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/bin/rake:19:in `<main>'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/bin/ruby_noexec_wrapper:14:in `eval'
/Users/Luigi/.rvm/gems/ruby-1.9.3-p429@test/bin/ruby_noexec_wrapper:14:in `<main>'
上面提到的特定代码行位于第 179 行,它位于从第 165 行开始的循环内,而循环位于从第 90 行开始的循环内。