debugging ActiveRecord.save failure

Trying to debug a ActiveRecord problem with creating new records:

a = Appliance.new(:serial => '0105-0000-0000-aaaa')

=> #<Appliance id: nil, serial: "0105-0000-0000-aaaa", kickstart_times: 0, first_kickstart_date: nil, last_kickstart_date: nil, pemfile: nil, lspci: nil, verify: nil, created_at: nil, updated_at: nil, kickstart_mode: "disabled", lspci_log: nil, verify_log: nil, ks_log: nil, status: nil>

a.save

=> false

a.save!

ActiveRecord::RecordNotSaved: ActiveRecord::RecordNotSaved   from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2206:in `save_without_validation!'   from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/validations.rb:911:in `save_without_dirty!'   from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/dirty.rb:83:in `save_without_transactions!'   from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:110:in `save!'   from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction'   from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:79:in `transaction'   from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:98:in `transaction'   from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:110:in `save!'   from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:118:in `rollback_active_record_state!'   from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/transactions.rb:110:in `save!'   from (irb):3

a.errors.full_messages

=>

I can edit/delete records via ActiveRecord just fine, and creating records manually via the sqlite3 shell works fine. Any suggestions on how to figure out what is causing the problem? I'm surprised there aren't any listed errors.

Hi Aaron,

Aaron Turner wrote:

Trying to debug a ActiveRecord problem with creating new records:

>> a = Appliance.new(:serial => '0105-0000-0000-aaaa') => #<Appliance id: nil, serial: "0105-0000-0000-aaaa", kickstart_times: 0, first_kickstart_date: nil, last_kickstart_date: nil, pemfile: nil, lspci: nil, verify: nil, created_at: nil, updated_at: nil, kickstart_mode: "disabled", lspci_log: nil, verify_log: nil, ks_log: nil, status: nil>

>> a.save => false <snip> I can edit/delete records via ActiveRecord just fine, and creating records manually via the sqlite3 shell works fine. Any suggestions on how to figure out what is causing the problem? I'm surprised there aren't any listed errors.

First thing I'd suspect is that my validations were doing something I didn't expect. Try ... a.save_with_validations(false) If the record saves successfully, look at your validations. If not, you'll need to post some additional info about your models and migrations for us to be much help.

Best regards, Bill

Thanks Bill. I actually tracked down the problem to a before_create method which was returning false.