1. Nicolas Cavigneaux
  2. Acts_as_nice_url

Wiki

Clone wiki

Acts_as_nice_url / Home

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 :

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

or install it system-wide :

$ sudo gem install acts_as_nice_url

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

config.gem 'acts_as_nice_url'

Example

In your model :

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

then in your views :

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

or

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 :

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

or

player_path(@player.id)

Other

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

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

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

Updated