我是第一次接触friendly-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字段,我真正需要改变的是什么?
发布于 2014-04-10 18:22:24
我也不喜欢这个名字,它听起来像一只赤裸的蜗牛..:slug_column选项应该可以工作。如果您不想使用默认的"slug“列,则可以按如下方式定义它:
friendly_id :title, use: :slugged, slug_column: :permalink
def change
add_column :posts, :permalink, :string
add_index :posts, :permalink
endhttps://stackoverflow.com/questions/22981086
复制相似问题