Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 35 lines (23 sloc) 703 Bytes

dm-is-sluggble

DataMapper plugin that allows records to be found as a slug, mostly used in pretty urls.

Example DataMapper resource (i.e. model)

# /app/models/post.rb
class Post
  include DataMapper::Resource

  property :id, Serial
  property :slug, String

  is :sluggable

end

@post = Post.create
@post.slug # => "@1"
Post.by_slug # => @post

@post.update_attributes(:slug => 'some-slug-here')
@post.slug # => "some-slug-here"
Post.by_slug # => @post

Example Merb route

# /config/routes.rb
identify(Post => :slug) do
  resources :posts
end

# url(:post, 1) => /posts/some-slug-here