在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
实现效果:http://127.0.0.1:3000/article/1 => http://127.0.0.1:3000/article/书名 (1)Rails 4.0的friendly_id的版本必须是5.0以上。在Gemfile中加入, gem 'friendly_id','~> 5.0.0.beta' (2)运行, rails g migration add_slug_to_articles slug:string
rake db:migrate
(3)db/migrate/add_slug_to_articles.rb
add_column :articles, :slug, :string
add_index :articles, :slug
(4)models/article.rb
class Article < ActiveRecord::Base extend FriendlyId friendly_id :name, :use => :slugged def should_generate_new_friendly_id? new_record? end end 相关链接: http://railscasts.com/episodes/314-pretty-urls-with-friendlyid http://railscasts.com/episodes/314-pretty-urls-with-friendlyid?view=asciicast |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论