0.0
No commit activity in last 3 years
No release in over 3 years
It uses ActiveSupport's String#parameterize to create the slug. There are no validations. No slug history. No extra tables or models.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0.8.7
~> 2.11
~> 1.3

Runtime

 Project Readme

Parameterize

The simplest permalink/slug solution for ActiveRecord >= 3.0.

It uses ActiveSupport's String#parameterize to create the slug. There are no validations. No slug history. No extra tables or models.

Getting Started

# Gemfile
gem 'parameterize'
$ bundle install
$ rails generate model User name:string param:string
# Parameterize requires a string column named 'param'
# models/user.rb
class User < ActiveRecord::Base
  parameterize :name
end

# elsewhere
user = User.new :name => 'John Doe'
user.valid?
user.param = 'john-doe'
user.to_param = 'john-doe'

Notes

Validations are not included. I prefer to be able to customize my validations directly in the model. The most common validations you would add are:

class Post < ActiveRecord::Base
  parameterize
  validates_presence_of :param
  validates_uniqueness_of :param
end

You could easily use Babosa's #to_identifier or Stringex's #to_url instead of ActiveSupport's #parameterize by just aliasing the method you want to use:

require 'babosa'
class String
  alias :parameterize :to_identifier
end

There is also a Shoulda-style RSpec matcher available for use in your specs:

# spec_helper.rb
require 'parameterize/matcher'

# post_spec.rb
describe Post do
  it { should parameterize(:title) }
end

Copyright

Copyright (c) 2011 Peter Browne. See LICENSE for details.