0
Class Product < ActiveRecord::Base
  has_friendly_id :name, :use_slug => true
end

What is the most efficient method to store the slugs within the 'products' table. I have complex find queries, and the joins with the 'slugs' table give me performance bottlenecks.

Matenia Rossides
  • 1,406
  • 9
  • 35
astropanic
  • 10,800
  • 19
  • 72
  • 132

2 Answers2

2

Ok, I know this is an old question, but just wanted to note, for others that may stumble across this:

The code snippet in the question is from FriendlyId 3.x in which case you would add a column to your table (call it anything except for slug ... I prefer to use cached_slug) as a string and update the model to show

Class Product < ActiveRecord::Base
  has_friendly_id :name, :use_slug => true, :cache_column => 'cached_slug'
end

As of friendly_id 4.x, you simply just add a slug column as a string to the table, and use the new syntax:

eg:

Class Product < ActiveRecord::Base
  extend FriendlyId
  friendly_id :name, :use => :slugged
end

There are a whole bunch of options and ways to get the most out of friendly_id including historical records (to avoid 404s) etc ...

More information: http://rubydoc.info/github/norman/friendly_id/master/frames

Matenia Rossides
  • 1,406
  • 9
  • 35
1

Friendly_id now has built-in slug caching.

Norman Clarke
  • 436
  • 2
  • 4