Bounga / Acts_as_nice_url (http://bitbucket.org/Bounga/acts_as_nice_url/)

A Ruby on Rails plugin to generate pretty URLs from models data

NiceUrl

This acts_as extension provides the capabilities for creating a nice url based on an attribute of the current object. You can set / unset the object id in front of the URL and choose the object attribute to use to generate the URL.

Installation

In your Rails app root, use the following command-line :

1
2
cd vendor/plugins/
hg clone http://bitbucket.org/Bounga/acts_as_nice_url/

or install it system-wide :

1
$ sudo gem install acts_as_nice_url

and require it in Rails::Initializer (environment.rb) :

1
config.gem 'acts_as_nice_url'

Example

In your model :

1
2
3
class Player < ActiveRecord::Base
  acts_as_nice_url :id => false, :title => :full_name
end

then in your views :

1
link_to(:controller => :players, :action => :show, :id => @player)

or

1
player_path(@player)

Use id only in some case

If you want to use the id only in the generated URL, you have to fill the id parameter with the id only, not the full object :

1
link_to(:controller => :players, :action => :show, :id => @player.id)

or

1
player_path(@player.id)

Other

If you want to contribute you should take a look at:

You can take a look at RDoc too.

Problems, comments, and suggestions are welcome on the ticket system

Copyright (c) 2008 Nicolas Cavigneaux, released under the MIT license


This revision is from 2008-12-08 16:11