Skip to content

smtlaissezfaire/slugify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slugify

Generate slugs for your models

Install as a rails plugin or or as a gem

…then add the following to a model you’d like to slug:

class MyClass < ActiveRecord::Base
  include Slugify
  slugify :title
end

Throw it in vendor/plugins (with script/plugin install, braid, submodules, or whatever your preferred installation method), and add the following to a model you’d like to slug:

class MyClass < ActiveRecord::Base
  include Slugify
  slugify :title
end

If you are using slugify in multiple models, you may want to mix it into ActiveRecord::Base:

ActiveRecord::Base.instance_eval do
  include Slugify
end

class MyClass < ActiveRecord::Base
  slugify :title
end

Examples

class Page < ActiveRecord::Base
  include Slugify

  validates_presence_of :title

  slugify :title
end

Page.create(:title => "Foo")
# => #<Page id: 1, title: "Foo", slug: "foo">

Page.create(:title => "Foo")
# => #<Page id: 1, title: "Foo", slug: "foo-0">

Using a different slug column

slugify :my_column, :slug_column => :bar

Scoping:

slugify :slug_column, :scope => :col_one
slugify :slug_column, :scope => [:col_one, :col_two]

Conditional slug generation:

slugify :my_column, :when => lambda { |my_record| my_record.published? }

Contributors

kule - STI Issues [Github Issue #1]

About

Slug generation for ActiveRecord models

Resources

License

GPL-3.0, MIT licenses found

Licenses found

GPL-3.0
GPL_LICENSE
MIT
MIT_LICENSE

Stars

Watchers

Forks

Packages

No packages published

Languages