我是友善ID的新手,我在post.rb模型中有这个
extend FriendlyId
friendly_id :title, use: :slugged
和friendly_id生成器迁移
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
我通过此迁移添加了slug属性
def change
add_column :posts, :slug, :string
add_index :posts, :slug
Post.find_each(&:save)
end
但我想使用永久链接而不是像post.permalink这样的slug字段 我真的需要改变什么?
答案 0 :(得分:0)
我也不喜欢名字slug,它听起来像一只赤裸的蜗牛..:slug_column选项应该有用。如果您不想使用默认的" slug"然后你可以按如下方式定义它:
friendly_id :title, use: :slugged, slug_column: :permalink
def change
add_column :posts, :permalink, :string
add_index :posts, :permalink
end