szajbus / to_param

Provides simple macro to define all methods you may potentially need to fully use Rails to_param mechanism.

This URL has Read+Write access

name age message
file MIT-LICENSE Loading commit data...
file README
file Rakefile
file init.rb
directory lib/
directory test/
README
ToParam
=======

ToParam plugin provides simple macro to define all methods you may potentially need to fully use to_param mechanism.
Intended but not limited to work with Ruby on Rails and ActiveRecord.

Installation
============

  script/plugin install git://github.com/szajbus/to_param.git

Example
=======

  class Article < Active::Record
    to_param :slug
  end
  
The code above is equivalent to:

  class Article < Active::Record
    def to_param
      slug
    end
    
    def self.find_by_param(*args)
      find_by_slug(args)
    end
    
    def self.find_by_param!(*args)
      find_by_slug!(args)
    end
    
    def self.find_all_by_param(*args)
      find_all_by_slug(args)
    end
    
    def self.find_all_by_param!(*args)
      find_all_by_slug!(args)
    end
  end

So this plugin is just a time-and-space-saver, not much magic here.

Copyright (c) 2009 MichaƂ Szajbe, released under the MIT license