norman/friendly_id — Issue #210: Using friendly_id 4's History -- doesn't add #slug method?
Author: joevandyk
Created: 2012-01-13 20:33:32+00:00
State: open

Maybe I'm not using the right options? I'm following the instructions in the History docs.

```
class Product < ActiveRecord::Base
extend FriendlyId
friendly_id :name, :use => :history
...
end

1.9.1 :011 > p = Product.first
Product Load (0.9ms) SELECT "products".* FROM "products" LIMIT 1
=> # app.product_path(p)
NoMethodError: undefined method `slug' for #
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activemodel/lib/active_model/attribute_methods.rb:407:in `method_missing'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/attribute_methods.rb:122:in `method_missing'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/gems/friendly_id-4.0.0/lib/friendly_id/base.rb:235:in `friendly_id'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/gems/friendly_id-4.0.0/lib/friendly_id/base.rb:243:in `to_param'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/actionpack/lib/action_dispatch/routing/route_set.rb:398:in `block in '
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/gems/journey-1.0.0/lib/journey/formatter.rb:31:in `call'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/gems/journey-1.0.0/lib/journey/formatter.rb:31:in `block (2 levels) in generate'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/gems/journey-1.0.0/lib/journey/formatter.rb:30:in `each'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/gems/journey-1.0.0/lib/journey/formatter.rb:30:in `block in generate'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/gems/journey-1.0.0/lib/journey/formatter.rb:58:in `match_route'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/gems/journey-1.0.0/lib/journey/formatter.rb:16:in `generate'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/actionpack/lib/action_dispatch/routing/route_set.rb:491:in `generate'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/actionpack/lib/action_dispatch/routing/route_set.rb:532:in `generate'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/actionpack/lib/action_dispatch/routing/route_set.rb:557:in `url_for'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/ssl_requirement-1a8af793f8d8/lib/url_for.rb:43:in `url_for_with_non_ssl_host'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/ssl_requirement-1a8af793f8d8/lib/url_for.rb:32:in `url_for_with_secure_option'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/actionpack/lib/action_dispatch/routing/url_for.rb:148:in `url_for'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/actionpack/lib/action_dispatch/routing/route_set.rb:202:in `product_path'
from (irb):12
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/railties/lib/rails/commands/console.rb:47:in `start'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/railties/lib/rails/commands/console.rb:8:in `start'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/railties/lib/rails/commands.rb:41:in `'
from script/rails:6:in `require'
from script/rails:6:in `

'1.9.1 :013 > p.slug
NoMethodError: undefined method `slug' for #
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activemodel/lib/active_model/attribute_methods.rb:407:in `method_missing'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/attribute_methods.rb:122:in `method_missing'
from (irb):13
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/railties/lib/rails/commands/console.rb:47:in `start'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/railties/lib/rails/commands/console.rb:8:in `start'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/railties/lib/rails/commands.rb:41:in `'
from script/rails:6:in `require'
from script/rails:6:in `

'

1.9.1 :014 > p.friendly_id
NoMethodError: undefined method `slug' for #
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activemodel/lib/active_model/attribute_methods.rb:407:in `method_missing'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/attribute_methods.rb:122:in `method_missing'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/gems/friendly_id-4.0.0/lib/friendly_id/base.rb:235:in `friendly_id'
from (irb):14
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/railties/lib/rails/commands/console.rb:47:in `start'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/railties/lib/rails/commands/console.rb:8:in `start'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/railties/lib/rails/commands.rb:41:in `'
from script/rails:6:in `require'
from script/rails:6:in `

'

1.9.1 :015 > p.slugs
FriendlyId::Slug Load (0.8ms) SELECT "slugs".* FROM "slugs" WHERE "slugs"."sluggable_id" = 21 AND "slugs"."sluggable_type" = 'Product' ORDER BY "slugs".id DESC
=> [#]

1.9.1 :018 > p = Product.find 'magazine-1'
Product Load (0.5ms) SELECT "products".* FROM "products" WHERE "products"."slug" = 'magazine-1' LIMIT 1
PGError: ERROR: column products.slug does not exist
LINE 1: SELECT "products".* FROM "products" WHERE "products"."slug...
^
: SELECT "products".* FROM "products" WHERE "products"."slug" = 'magazine-1' LIMIT 1
ActiveRecord::StatementInvalid: PGError: ERROR: column products.slug does not exist
LINE 1: SELECT "products".* FROM "products" WHERE "products"."slug...
^
: SELECT "products".* FROM "products" WHERE "products"."slug" = 'magazine-1' LIMIT 1
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:1106:in `async_exec'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:1106:in `exec_no_cache'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:650:in `block in exec_query'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `exec_query'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:1201:in `select'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:16:in `select_all'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/querying.rb:38:in `block in find_by_sql'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/explain.rb:38:in `logging_query_plan'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/querying.rb:37:in `find_by_sql'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/relation.rb:170:in `exec_queries'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/relation.rb:159:in `block in to_a'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/explain.rb:38:in `logging_query_plan'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/relation.rb:158:in `to_a'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/relation/finder_methods.rb:377:in `find_first'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/relation/finder_methods.rb:122:in `first'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/gems/friendly_id-4.0.0/lib/friendly_id/history.rb:90:in `find_one'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/relation/finder_methods.rb:311:in `find_with_ids'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/relation/finder_methods.rb:107:in `find'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/activerecord/lib/active_record/querying.rb:5:in `find'
from (irb):18
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/railties/lib/rails/commands/console.rb:47:in `start'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/railties/lib/rails/commands/console.rb:8:in `start'
from /Users/joe/projects/tanga/bundler/ruby/1.9.1/bundler/gems/rails-70631e723ca9/railties/lib/rails/commands.rb:41:in `'
from script/rails:6:in `require'
```