0

I am new to friendly-id and i have this in my post.rb model

extend FriendlyId
friendly_id :title, use: :slugged

and friendly_id generator migration is

def change
  create_table :friendly_id_slugs do |t|
    t.string   :slug,           :null => false
    t.integer  :sluggable_id,   :null => false
    t.string   :sluggable_type, :limit => 50
    t.string   :scope
    t.datetime :created_at
  end
  add_index :friendly_id_slugs, :sluggable_id
  add_index :friendly_id_slugs, [:slug, :sluggable_type]
  add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], :unique => true
  add_index :friendly_id_slugs, :sluggable_type
end

and i added slug attribute with this migration

def change
  add_column :posts, :slug, :string
  add_index :posts, :slug
  Post.find_each(&:save)
end

but I want use permalink instead of slug field like post.permalink what i really need to change?

Asnad Atta
  • 3,855
  • 1
  • 32
  • 49

1 Answers1

0

I don't like the name slug, either, it sounds like a naked snail.. The :slug_column option should work. If you do not want to use the default "slug" column then you can define it as follows:

friendly_id :title, use: :slugged, slug_column: :permalink

def change
  add_column :posts, :permalink, :string
  add_index :posts, :permalink
end
0x4a6f4672
  • 27,297
  • 17
  • 103
  • 140