Adding pretty URIs to your blog
Samstag, 16. April 2011, 13:18 Uhr | roberto@vasquez-angel.de |To add pretty urls to your blogs posts, you can use the friendly_id
gem, that can be found here.
The documentation is really good, and installing was straight:
1.Installation
Add the gem to your application. In your Rails.root/Gemfile
:
gem "friendly_id", "~> 3.2.1"
Install your bundle:
$> bundle install
Run the friendly id installer:
$> rails g friendly_id
Migrate:
$> rake db:migrate
2.Adding slugs to the post model
Edit Rails.root/app/models/post.rb
:
class Post < ActiveRecord::Base has_friendly_id :title, :use_slug => true, :approximate_ascii => true, :ascii_approximation_options => :german # support for german umlauts
Generate the slugs for existing posts:
$> rake friendly_id:make_slugs MODEL=Post
3.Making your posts accessible through nice URIs
There is no step three :)