Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oleander/to_param-rb
A one-liner solution for ActiveRecord::Base#to_param
https://github.com/oleander/to_param-rb
Last synced: about 2 months ago
JSON representation
A one-liner solution for ActiveRecord::Base#to_param
- Host: GitHub
- URL: https://github.com/oleander/to_param-rb
- Owner: oleander
- License: mit
- Created: 2013-01-18T00:22:24.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-01-12T21:05:31.000Z (almost 11 years ago)
- Last Synced: 2024-10-31T13:25:12.688Z (2 months ago)
- Language: Ruby
- Size: 160 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# to_param
A one-liner solution for `ActiveRecord::Base#to_param`.
## Usage
### Default format
``` ruby
class User < ActiveRecord::Base
# ...
to_param :name
endUser.create(name: "Linus").to_param # => "1-linus"
```### Custom format
``` ruby
class User < ActiveRecord::Base
# ...
to_param "Feel-lucky-:name"
endUser.create(name: "punk").to_param # => "feel-lucky-punk"
```### Static value
``` ruby
class User < ActiveRecord::Base
# ...
to_param "static"
endUser.create(name: "Linus").to_param # => "static"
```## Note
`ActiveRecord::Base.to_param` uses [#parameterize](http://apidock.com/rails/ActiveSupport/Inflector/parameterize) under the hood, so you don't have to worry about escaping.
## How do install
[sudo] gem install to_param
## Requirements
*to_param* is tested in *OS X 10.8.2* using Ruby *1.9.2* and Rails *3.2*.
## License
*to_param* is released under the *MIT license*.