This is the first time that I blog in english, so please correct me if I write something wrong. Suggestions are welcome too =)
CouchDB automatically generates UUIDs if none are provided. Usually, it’s recommended because some things like replication. However, we can do better for users. UUIDs are ugly, then we can create friendly urls.
CouchRest Model Slug is a simple gem to generate better urls using CouchRest Model in an easy way. I created this gem based on Mongoid Slug.
Getting Started
Add to Gemfile
gem "couchrest_model_slug", "~> 0.0.2"
A simple example
class Post < CouchRest::Model::Base include CouchRest::Model::Slug property :title property :text slug :title end
Querying
p = Post.create(:title => "CouchDB Time To Relax") p.to_param # => "couchdb-time-to-relax" Post.find("couchdb-time-to-relax") # =>#<Post slug: "couchdb-time-to-relax", title: "CouchDB...
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, text: "post with no slug", _id: "9fdfdd090897680de59091c8c98ff064"... Post.find("9fdfdd090897680de59091c8c98ff064") # => #<Post slug: "", title: nil, text: "post with no slug", _id: "9fdfdd090897680de59091c8c98ff064"...
See the github page for more information https://github.com/lucasrenan/couchrest-model-slug