Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bumi/find_by_param
(deprecated) Find_by_param is a nice and easy way to handle permalinks and dealing with searching for to_param values
https://github.com/bumi/find_by_param
Last synced: 4 days ago
JSON representation
(deprecated) Find_by_param is a nice and easy way to handle permalinks and dealing with searching for to_param values
- Host: GitHub
- URL: https://github.com/bumi/find_by_param
- Owner: bumi
- License: mit
- Created: 2008-03-25T12:26:27.000Z (over 16 years ago)
- Default Branch: master
- Last Pushed: 2011-09-19T15:14:36.000Z (about 13 years ago)
- Last Synced: 2024-10-31T08:26:22.247Z (13 days ago)
- Language: Ruby
- Homepage:
- Size: 144 KB
- Stars: 30
- Watchers: 4
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- Changelog: History.txt
- License: MIT-LICENSE
Awesome Lists containing this project
README
= find_by_param
_find_by_param_ helps you dealing with permalinks and finding objects by our
permalink valueclass Post < ActiveRecord:Base
make_permalink :with => :title
endnow 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.== Installation
=== Via RubyGems
% gem install find_by_param
=== Building your own
% gem build find_by_param.gemspec
% gem install find_by_param-VERSION.gem=== As Rails plugin
% script/plugin install git://github.com/bumi/find_by_param.git
find_by_param is known to work with Rails 2.3, 3.0 and 3.1.
== Examples
=== Configuration
make_permalink :with => :login
make_permalink :with => :title, :prepend_id => true
make_permalink :with => :name, :forbidden => %w(new edit)=== Client code
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 valuesPost.find_by_param("hey-ho-lets-go") #=>
Post.find_by_param("is-not-there") #=> nil
Post.find_by_param!("is-not-there") #=> raises ActiveRecord::RecordNotFound== Basic Documentation
=== Options for make_permalink
The following options may be used, when configuring the permalink generation
with +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.* :param_size => [Number]
Desired maximum size of the permalink, default is 50.* :escape => [true|false]
Do you want to escape the permalink value? (strip chars like
öä?&) - actually you must do that* :forbidden => [Regexp|String|Array of Strings]
Define which values should be forbidden. This is useful when combining user
defined values to generate permalinks in combination with restful routing.
Make sure, especially in the case of a Regexp argument, that values may
become valid by adding or incrementing a trailing integer.=== Class methods provided by _find_by_param_
The following methods are added as public methods to all classes containing a
permalink field.* find_by_param(id)
Look up a value by its permalink value, returns matching instance or
+nil+, if none is found.* find_by_param!(id)
Look up a value by its permalink value, returns matching instance or
raises ActiveRecord::RecordNotFound, if none is found.=== 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 testsCopyright (c) 2007 [Michael Bumann - Railslove.com], released under the MIT license