No commit activity in last 3 years
No release in over 3 years
A simple gem to generate slugs using couchrest model, based on mongoid_slug.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

CouchRest Model Slug is a simple gem to generate better urls using CouchRest Model in an easy way. It’s based on Mongoid Slug github.com/papercavalier/mongoid-slug

Time to relax with beautiful urls.

Getting Started¶ ↑

Add to Gemfile

gem "couchrest_model_slug", "~> 0.0.3"

A model example

class Post < CouchRest::Model::Base
  include CouchRest::Model::Slug

  property :title
  property :summary
  property :text

  slug :title, :summary
end

It’s all you need to get things working =)

Querying¶ ↑

p = Post.create(:title => "CouchDB", :summary => "Time to relax!")
p.to_param # => "couchdb-time-to-relax"

Post.find("couchdb-time-to-relax") # =>#<Post slug: "couchdb-time-to-relax", title: "CouchDB"...

Special feature¶ ↑

CouchRest Model Slug was made to work with or without slugged value, then it uses the id to keep things running with no problems.

Post.create(:text => "post without slug") # => #<Post slug: "", title: nil, summary: nil, text: "post with no slug", _id: "9fdfdd090897680de59091c8c98ff064"...

Post.find("9fdfdd090897680de59091c8c98ff064") # => #<Post slug: "", title: nil, summary: nil, text: "post with no slug", _id: "9fdfdd090897680de59091c8c98ff064"...

Notes¶ ↑

CouchRest Model Slug automatically adds a property called slug into your model to store the slugged value. Then you can call the slug property directly.

p = Post.create(:title => "CouchDB", :summary => "Time to relax!")
p.slug # => "couchdb-time-to-relax"

If you want to be more explicit, you can query using find_by_slug magic method:

Post.find_by_slug("couchdb-time-to-relax") # =>#<Post slug: "couchdb-time-to-relax", title: "CouchDB"...