Generate slugs for your models
…then add the following to a model you’d like to slug:
classMyClass<ActiveRecord::BaseincludeSlugifyslugify:titleend
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:
classMyClass<ActiveRecord::BaseincludeSlugifyslugify:titleend
If you are using slugify in multiple models, you may want to mix it into ActiveRecord::Base:
ActiveRecord::Base.instance_evaldoincludeSlugifyendclassMyClass<ActiveRecord::Baseslugify:titleend
classPage<ActiveRecord::BaseincludeSlugifyvalidates_presence_of:titleslugify:titleendPage.create(:title=>"Foo") # => #<Page id: 1, title: "Foo", slug: "foo">Page.create(:title=>"Foo") # => #<Page id: 1, title: "Foo", slug: "foo-0">
slugify:my_column, :slug_column=>:bar
slugify:slug_column, :scope=>:col_oneslugify:slug_column, :scope=> [:col_one, :col_two]
slugify:my_column, :when=>lambda { |my_record|my_record.published? }
kule - STI Issues [Github Issue #1]