Project

sluggerize

0.0
No commit activity in last 3 years
No release in over 3 years
Creates a slug from the specified column of any model.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Sluggerize

A simple plugin that automatically generates a url friendly version of a column (a slug) for a model on create.

Usage

sluggerize :source_column, [options]

Source Column

If you don't provide a source column, it will default to looking for a "title" column.

Options

  • as_params [False] If true, this will be used as the id of the object when creating URLs and you will be able to Object.find(slug)
  • substitution_char - [-] The character to use when replacing spaces and other unsupported characters

Example

create_table "projects" do |t|
  t.string   "title"
  t.string   "slug"
end

class Project < ActiveRecord::Base
  sluggerize
end

Project.create(:title => 'A Very Happy Project')
Project.first.slug
=> 'a-very-happy-project'

Copyright (c) 2011 Jeremy Hubert, released under the MIT license