public
Description: Find_by_param is a nice and easy way to handle permalinks and dealing with searching for to_param values
Homepage:
Clone URL: git://github.com/bumi/find_by_param.git
Click here to lend your support to: find_by_param and make a donation at www.pledgie.com !
commit  cd247310c49690387be39e7681b7a82a337c54bf
tree    71a352f7963474d534ed6d356f2f7e1252625991
parent  8e609449a87e902ca3e90c1ed4245587f5e81a10
name age message
file MIT-LICENSE Sat Aug 16 16:44:53 -0700 2008 remove multiple dashes in escaped URL [Michael Bumann]
file README Sat Nov 01 18:33:14 -0700 2008 added note about STI issue to readme [Michael Bumann]
file Rakefile Tue Mar 25 07:15:37 -0700 2008 inital commit [Michael Bumann]
file init.rb Mon Oct 27 09:32:09 -0700 2008 rely on active_support/multibyte for slug gener... [Michael Bumann]
file install.rb Tue Mar 25 07:15:37 -0700 2008 inital commit [Michael Bumann]
directory lib/ Mon Mar 09 13:32:08 -0700 2009 fixing minor issue with active_support paramete... [Michael Bumann]
directory tasks/ Tue Mar 25 07:15:37 -0700 2008 inital commit [Michael Bumann]
directory test/ Wed Nov 12 17:43:44 -0800 2008 improve validation and remove stupid permalink ... [Michael Bumann]
file uninstall.rb Tue Mar 25 07:15:37 -0700 2008 inital commit [Michael Bumann]
FindByParam
===========

Find_by_param helps you dealing with permalinks and finding objects by our permalink value

class Post < ActiveRecord:Base
 make_permalink :with => :title
end

now you can do Post.find_by_param(...)

If you have a permalink-column find_by_param saves the permalink there and uses that otherwise it just uses the provided 
attribute.


Example
===========

Post.create(:title => "hey ho let's go!").to_param #=> "hey-ho-lets-go"  (to_param is the method Rails calls to create 
the URL values)

Post.find_by_param("hey-ho-lets-go") #=> <Post>

Post.find_by_param("is-not-there") #=> nil
Post.find_by_param!("is-not-there") #=> raises ActiveRecord::RecordNotFound

examples:

make_permalink :with => :login
make_permalink :with => :title, :prepend_id=>true


options for make_permalink:

:with: (required) The attribute that should be used as permalink
:field: The name of your permalink column. make_permalink first checks if there is a column. 
:prepend_id: [true|false] Do you want to prepend the ID to the permalink? for URLs like: posts/123-my-post-title - 
find_by_param uses the ID column to search.
:escape: [true|false] Do you want to escape the permalink value? (strip chars like öä?&?) - actually you must do that




Issues
=======

* Alex Sharp (http://github.com/ajsharp) pointed to an issue with STI. Better call make_permalink in every child class 
and not only in the parent class..
* write nice docs
* write nicer tests

Copyright (c) 2007 [Michael Bumann - Railslove.com], released under the MIT license