Project

to_param

0.0
No commit activity in last 3 years
No release in over 3 years
A one-liner solution for ActiveRecord::Base#to_param
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0
 Project Readme

to_param

A one-liner solution for ActiveRecord::Base#to_param.

Usage

Default format

class User < ActiveRecord::Base
  # ...
  to_param :name
end

User.create(name: "Linus").to_param # => "1-linus"

Custom format

class User < ActiveRecord::Base
  # ...
  to_param "Feel-lucky-:name"
end

User.create(name: "punk").to_param # => "feel-lucky-punk"

Static value

class User < ActiveRecord::Base
  # ...
  to_param "static"
end

User.create(name: "Linus").to_param # => "static"

Note

ActiveRecord::Base.to_param uses #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.