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

NoMethodError caught when I'm trying destroy the rated object #3

Open
wazery opened this issue Jul 30, 2014 · 0 comments
Open

NoMethodError caught when I'm trying destroy the rated object #3

wazery opened this issue Jul 30, 2014 · 0 comments

Comments

@wazery
Copy link
Owner

wazery commented Jul 30, 2014

Issue by monikaszalas
Monday Dec 03, 2012 at 13:57 GMT
Originally opened as muratguzel#10


I've decided using gem letsrate in my app, but I have some problem, probably caused by gem.

First some code:

I've got a model Article:

class Article < ActiveRecord::Base
  letsrate_rateable "quality"
  ...
end

and model User (generated by Devise):

class User < ActiveRecord::Base
  letsrate_rater
  ...
end

I've used generator according to readme instructions:

rails g letsrate user

Everything works great until I try destroy my article object, then I've got this error:

>> Article.last.destroy
Article Load (0.4ms)  SELECT `articles`.* FROM `articles` ORDER BY `articles`.`id` DESC LIMIT 1
   (0.1ms)  BEGIN
  Rate Load (0.4ms)  SELECT `rates`.* FROM `rates` WHERE `rates`.`rateable_id` = 1 AND `rates`.`rateable_type` = 'Article' AND `rates`.`dimension` IS NULL
  SQL (0.3ms)  DELETE FROM `rates` WHERE `rates`.`id` = 2
  RatingCache Load (1.2ms)  SELECT `rating_caches`.* FROM `rating_caches` WHERE `rating_caches`.`cacheable_id` = 1 AND `rating_caches`.`cacheable_type` = 'Article' AND `rating_caches`.`dimension` IS NULL LIMIT 1
  SQL (1.0ms)  DELETE FROM `rating_caches` WHERE `rating_caches`.`id` = 2
  Rate Load (0.3ms)  SELECT `rates`.* FROM `rates` WHERE `rates`.`rateable_id` = 1 AND `rates`.`rateable_type` = 'Article' AND `rates`.`dimension` = 'quality'
  Rate Load (0.3ms)  SELECT `rates`.* FROM `rates` WHERE `rates`.`rateable_id` = 1 AND `rates`.`rateable_type` = 'Article' AND `rates`.`dimension` = 'quality'
   (0.5ms)  ROLLBACK
NoMethodError: undefined method `association_class' for nil:NilClass
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/associations.rb:159:in `association'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/associations/builder/has_one.rb:49:in `has_one_dependent_destroy_for_quality_average'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.1.6/lib/active_support/callbacks.rb:422:in `_run_destroy_callbacks'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.1.6/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/callbacks.rb:254:in `destroy'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/transactions.rb:236:in `block in destroy'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/connection_adapters/abstract/database_statements.rb:194:in `transaction'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/transactions.rb:208:in `transaction'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/transactions.rb:236:in `destroy'
  from (irb):1
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.1.6/lib/rails/commands/console.rb:45:in `start'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.1.6/lib/rails/commands/console.rb:8:in `start'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.1.6/lib/rails/commands.rb:40:in `<top (required)>'
  from /Users/xyz/projekty/dentist/script/rails:6:in `require'
  from /Users/xyz/projekty/dentist/script/rails:6:in `<top (required)>'
from -e:1:in `load'
  from -e:1:in `<main>'

The error occures no matter if I use quality dimension or not. I will be very grateful for your reply where the problem is.

PS. Im'using the newest version of gem (letsrate (1.0.7))

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

1 participant