RISCfuture/slugalicious — Issue #2: NoMethodError: undefined method `abstract_class?' for Object:Class
Author: hazah
Created: 2011-12-14 12:00:57+00:00
State: open

Stumbling upon this in rails 3.1.3. I know from the docs that only Rails 3.0 is supported. So far I've determined that it may have something to do with the setting of the primary key. I wouldn't mind contributing a patch for this, but cant tell where to start. So any pointers would be helpful. Hoping that you will take a look.

The line that triggers the issue is found in lib/slugalicious.rb: 197

slugs_in_use = if slugs.loaded? then
slugs.map(&:slug)
else
slugs.select(:slug).all.map(&:slug) # exception triggered here in #select
end

this is the model:

class Feed < ActiveRecord::Base
include Slugalicious
slugged :name
end

this is the full schema:

```
ActiveRecord::Schema.define(:version => 20111214111034) do

create_table "feeds", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "sessions", :force => true do |t|
t.string "session_id", :null => false
t.text "data"
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"

create_table "slugs", :force => true do |t|
t.integer "sluggable_id", :null => false
t.string "sluggable_type", :null => false
t.boolean "active", :default => true, :null => false
t.string "slug", :limit => 126, :null => false
t.string "scope", :limit => 126
t.datetime "created_at"
end

add_index "slugs", ["sluggable_type", "scope", "slug"], :name => "slugs_unique", :unique => true
add_index "slugs", ["sluggable_type", "sluggable_id", "active"], :name => "slugs_for_record"

end
```

Slugalicious version = 1.2.0

The full stack trace:

```
ruby-1.9.2-p180 :003 > Feed.create :name => 'live'
SQL (0.7ms) INSERT INTO "feeds" ("created_at", "name", "updated_at") VALUES (?, ?, ?) [["created_at", Wed, 14 Dec 2011 11:38:29 UTC +00:00], ["name", "live"], ["updated_at", Wed, 14 Dec 2011 11:38:29 UTC +00:00]]
NoMethodError: undefined method `abstract_class?' for Object:Class
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/base.rb:1348:in `class_of_active_record_descendant'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/base.rb:879:in `base_class'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/attribute_methods/primary_key.rb:25:in `reset_primary_key'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/attribute_methods/primary_key.rb:16:in `primary_key'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/reflection.rb:374:in `primary_key'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/reflection.rb:232:in `active_record_primary_key'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/associations/association_scope.rb:76:in `block in add_constraints'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/associations/association_scope.rb:51:in `each'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/associations/association_scope.rb:51:in `each_with_index'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/associations/association_scope.rb:51:in `add_constraints'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/associations/association_scope.rb:33:in `scope'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/associations/association.rb:99:in `association_scope'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/associations/association.rb:88:in `scoped'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/associations/collection_association.rb:76:in `select'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/associations/collection_proxy.rb:54:in `select'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/slugalicious-1.2.0/lib/slugalicious.rb:197:in `make_slug'
... 5 levels...
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/attribute_methods/dirty.rb:22:in `save'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/transactions.rb:241:in `block (2 levels) in save'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/transactions.rb:208:in `transaction'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/transactions.rb:241:in `block in save'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/transactions.rb:240:in `save'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.3/lib/active_record/base.rb:510:in `create'
from (irb):3
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
from /usr/local/rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.3/lib/rails/commands.rb:40:in `'
from script/rails:6:in `require'
from script/rails:6:in `

'
```