Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An error occurs when try to save a valid model #186

Closed
maxidr opened this issue Jan 2, 2013 · 8 comments
Closed

An error occurs when try to save a valid model #186

maxidr opened this issue Jan 2, 2013 · 8 comments
Milestone

Comments

@maxidr
Copy link

maxidr commented Jan 2, 2013

The application broken when try to save any model that contains has_paper_trail.
The error is always the same (related with nil.delete).

Error log

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.delete
..../gems/activerecord-3.0.17/lib/active_record/transactions.rb:334:in `restore_transaction_record_state'
..../gems/activerecord-3.0.17/lib/active_record/transactions.rb:253:in `rescue in rollback_active_record_state!'
..../gems/activerecord-3.0.17/lib/active_record/transactions.rb:257:in `rollback_active_record_state!'
..../gems/activerecord-3.0.17/lib/active_record/transactions.rb:239:in `save'
..../gems/activerecord-3.0.17/lib/active_record/associations/association_collection.rb:273:in `block in create'
..../gems/activerecord-3.0.17/lib/active_record/associations/association_collection.rb:503:in `block in create_record'
..../gems/activerecord-3.0.17/lib/active_record/associations/association_collection.rb:480:in `add_record_to_target_with_callbacks'
..../gems/activerecord-3.0.17/lib/active_record/associations/association_collection.rb:503:in `create_record'
..../gems/activerecord-3.0.17/lib/active_record/associations/association_collection.rb:271:in `create'
..../gems/paper_trail-2.6.4/lib/paper_trail/has_paper_trail.rb:158:in `record_create'
..../gems/activesupport-3.0.17/lib/active_support/callbacks.rb:422:in `_run_create_callbacks'
..../gems/activerecord-3.0.17/lib/active_record/callbacks.rb:277:in `create'
..../gems/activerecord-3.0.17/lib/active_record/persistence.rb:257:in `create_or_update'
..../gems/activerecord-3.0.17/lib/active_record/callbacks.rb:273:in `block in create_or_update'
..../gems/activesupport-3.0.17/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
..../gems/activerecord-3.0.17/lib/active_record/callbacks.rb:273:in `create_or_update'
..../gems/activerecord-3.0.17/lib/active_record/persistence.rb:60:in `save!'
..../gems/activerecord-3.0.17/lib/active_record/validations.rb:49:in `save!'
..../gems/activerecord-3.0.17/lib/active_record/attribute_methods/dirty.rb:30:in `save!'
..../gems/activerecord-3.0.17/lib/active_record/transactions.rb:245:in `block in save!'
..../gems/activerecord-3.0.17/lib/active_record/transactions.rb:292:in `block in with_transaction_returning_status'
..../gems/activerecord-3.0.17/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
..../gems/activerecord-3.0.17/lib/active_record/transactions.rb:207:in `transaction'
..../gems/activerecord-3.0.17/lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
..../gems/activerecord-3.0.17/lib/active_record/transactions.rb:245:in `save!'
..../gems/activerecord-3.0.17/lib/active_record/validations.rb:34:in `create!'
..../db/seeds.rb:161:in `<top (required)>'
..../gems/activesupport-3.0.17/lib/active_support/dependencies.rb:236:in `load'
..../gems/activesupport-3.0.17/lib/active_support/dependencies.rb:236:in `block in load'
..../gems/activesupport-3.0.17/lib/active_support/dependencies.rb:225:in `block in load_dependency'
..../gems/activesupport-3.0.17/lib/active_support/dependencies.rb:597:in `new_constants_in'
..../gems/activesupport-3.0.17/lib/active_support/dependencies.rb:225:in `load_dependency'
..../gems/activesupport-3.0.17/lib/active_support/dependencies.rb:236:in `load'
..../gems/activerecord-3.0.17/lib/active_record/railties/databases.rake:290:in `block (2 levels) in <top (required)>'

Bundle gem list

Gems included by the bundle:
  * Ascii85 (1.0.2)
  * abstract (1.0.0)
  * actionmailer (3.0.17)
  * actionpack (3.0.17)
  * activemodel (3.0.17)
  * activerecord (3.0.17)
  * activeresource (3.0.17)
  * activesupport (3.0.17)
  * addressable (2.3.2)
  * afipws (0.1.8)
  * annotate (2.5.0)
  * arel (2.0.10)
  * attrtastic (0.4.3)
  * aws-s3 (0.6.3)
  * aws-sdk (1.7.1)
  * bcrypt-ruby (3.0.1)
  * bourne (1.1.2)
  * builder (2.1.2)
  * bundler (1.1.4)
  * cancan (1.6.8)
  * capybara (2.0.1)
  * childprocess (0.3.6)
  * chunky_png (1.2.6)
  * cocaine (0.4.2)
  * cocoon (1.0.22)
  * coderay (1.0.8)
  * compass (0.12.2)
  * compass-rails (1.0.3)
  * crack (0.1.8)
  * daemons (1.1.9)
  * dalli (2.6.0)
  * devise (1.5.3)
  * devise_invitable (0.6.0)
  * diff-lcs (1.1.3)
  * erubis (2.6.6)
  * escape_utils (0.2.4)
  * eventmachine (1.0.0)
  * factory_girl (4.1.0)
  * factory_girl_rails (4.1.0)
  * ffi (1.2.0)
  * formtastic (2.0.2)
  * fssm (0.2.9)
  * geocoder (1.1.5)
  * guard (1.5.4)
  * guard-rspec (2.3.1)
  * gyoku (1.0.0)
  * haml (3.1.7)
  * haml-rails (0.3.4)
  * hashery (2.1.0)
  * hpricot (0.8.6)
  * httparty (0.9.0)
  * httpclient (2.3.0.1)
  * httpi (2.0.0)
  * i18n (0.5.0)
  * jquery-rails (2.1.4)
  * json (1.7.5)
  * kaminari (0.14.1)
  * libwebsocket (0.1.7.1)
  * listen (0.6.0)
  * lumberjack (1.0.2)
  * mail (2.2.19)
  * meta_search (1.0.6)
  * meta_where (1.0.4)
  * metaclass (0.0.1)
  * method_source (0.8.1)
  * mime-types (1.19)
  * mocha (0.10.5)
  * multi_json (1.5.0)
  * multi_xml (0.5.1)
  * nested_set (1.7.1)
  * nokogiri (1.5.5)
  * orm_adapter (0.0.7)
  * paper_trail (2.6.4)
  * paperclip (2.8.0)
  * pdf-reader (1.2.0)
  * pg (0.14.1)
  * polyglot (0.3.3)
  * prawn (0.12.0)
  * pry (0.9.10)
  * rack (1.2.5)
  * rack-mount (0.6.14)
  * rack-test (0.5.7)
  * rails (3.0.17)
  * railties (3.0.17)
  * rake (10.0.3)
  * rdoc (3.12)
  * rspec (2.12.0)
  * rspec-core (2.12.2)
  * rspec-expectations (2.12.1)
  * rspec-mocks (2.12.0)
  * rspec-rails (2.12.0)
  * ruby-ole (1.2.11.6)
  * ruby-rc4 (0.1.5)
  * rubyzip (0.9.9)
  * sass (3.2.3)
  * savon (0.8.3)
  * selenium-webdriver (2.27.2)
  * shoulda-matchers (1.4.2)
  * slop (3.3.3)
  * spreadsheet (0.7.5)
  * test-unit (2.5.3)
  * thin (1.5.0)
  * thor (0.14.6)
  * treetop (1.4.12)
  * ttfunk (1.0.3)
  * tzinfo (0.3.35)
  * uuidtools (2.1.3)
  * version (1.0.0)
  * warden (1.2.1)
  * webrat (0.7.3)
  * websocket (1.0.4)
  * wicked_pdf (0.8.0)
  * xml-simple (1.1.2)
  * xpath (1.0.0)

Fragment of a model:

class MoneyType < ActiveRecord::Base
  has_many :cashes
  belongs_to :account
  belongs_to :company

  scope :by_company, lambda { |company| where(:company_id => company.id) }

  attr_accessible :name, :company_id, :account_id, :is_cash

   has_paper_trail

    # more code

end

Can you help with this?

Thanks!!

@batter
Copy link
Collaborator

batter commented Jan 2, 2013

Can you please provide all of the code that exists on the model. This will help to determine debugging. Also, did you follow all of the steps listed in the install instructions? (Including migrating the database).

Another question is whether you setup an initializer in config/initializers/paper_trail.rb?

Also, does the error get raised when saving a model if you comment out the has_paper_trail directive?

I have a feeling that this is either being caused by a faulty callback, or a failure to complete all of the steps for the install generator.

@maxidr
Copy link
Author

maxidr commented Jan 3, 2013

hi @fullbridge-batkins !
I found the error, this is incompatible with the version gem because both define the class Version.
This is embarrassing because I report an issue in the another gem too, sorry!
Do you know any mode to workaround the name collision in Version class (add namespace I think)?

@batter
Copy link
Collaborator

batter commented Jan 3, 2013

@maxidr - Try upgrading to the most recent version of PaperTrail (2.7.0). Pull #183 was merged in, which may solve the issue.

That may not solve the issue, and this has been documented in #165, which I hope to tackle within a month or two.

@maxidr
Copy link
Author

maxidr commented Jan 3, 2013

@fullbridge-batkins excellent news!!! I try to upgrade to 2.7.0 and will tell my experience

thanks!!

@batter
Copy link
Collaborator

batter commented Jan 21, 2013

@maxidr - Did the upgrade to 2.7.0 fix your issues?

@maxidr
Copy link
Author

maxidr commented Jan 21, 2013

Sorry but I don't upgrade and try yet :(

@batter
Copy link
Collaborator

batter commented May 2, 2013

I'm gonna close this for now but please report back if you upgrade and are still encountering the issue and I'll see what we can do. The 3.0.0 release will have a namespaced Version class which should fix this.

@batter batter closed this as completed May 2, 2013
@brodock
Copy link

brodock commented Aug 6, 2013

this is related to #231

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants