Skip to content

botanicus/dm-is-sluggable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

This is plugin for easy creating unique slugs from other properties.

Initialization

You need to have DataMapper model with property slug. To set slug just use before create hook with set_slug model method. This method takes the slug as parameter. Use String#to_slug to get this parameter if you need.

class Post
  include DataMapper::Resource
  is :sluggable
  property :title, String
  property :slug,  String, :key => true
  before :create do
    set_slug(self.title.to_slug)
  end
end

So what exactly set_slug does? It look for given slug, if not found than save it, let say as “foo-bar”. If found, than increase number of iteraction and tries it again with “foo-bar-2”.

About

Creates unique slug from property. For DataMapper ORM.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages