Doing the simple stuff so you don't have to
Go to file
2011-12-02 07:15:27 -08:00
benchmarks Adding 2moro's benchmarks for dirty tracking 2011-04-20 12:33:30 +02:00
lib Improved auto_update_design_doc handling. 2011-12-01 09:19:15 -07:00
spec Merge remote branch 'refs/remotes/canonical/master' into design-mapper-more-auto-update-design-doc-aware 2011-11-29 08:22:30 -07:00
.gitignore Ignore all gems 2011-04-27 13:11:15 +02:00
.rspec Fixing time parsing issue for times without zone 2010-08-18 19:36:01 +02:00
couchrest_model.gemspec added rake to gemfile 2011-08-21 01:59:48 -03:00
Gemfile Adding Gemfile for development 2011-01-17 15:42:05 +01:00 update readme 2011-08-21 02:02:56 -03:00
init.rb Adds suppport for ActiveModel::Dirty and ::AttributeMethods 2010-09-16 17:30:43 -05:00
LICENSE added apache license 2008-09-11 21:31:59 -07:00
Rakefile Update Rakefile to use latest rspec. 2011-05-16 10:50:22 +02:00 adding config generator 2011-05-15 14:41:13 -03:00 Adding Sam and Will to 2010-07-28 21:39:10 -03:00
VERSION Updating histories and ensuring VERSION and date are good for 1.1.2 2011-07-23 17:38:49 +02:00

CouchRest Model: CouchDB, close to shiny metal with rounded edges

CouchRest Models adds additional functionality to the standard CouchRest Document class such as setting properties, callbacks, typecasting, and validations.


Please visit the documentation project at You're contributions to the documentation would be greatly appreciated!

General API:

See the update history for an up to date list of all the changes we've been working on recently.


Originally called ExtendedDocument, the new Model structure uses ActiveModel, part of Rails 3, for validations and callbacks.

If your project is still running Rails 2.3, you'll have to continue using ExtendedDocument as it is not possible to load ActiveModel into programs that do not use ActiveSupport 3.0.

CouchRest Model is only properly tested on CouchDB version 1.0 or newer.

WARNING: As of April 2011 and the release of version 1.1.0, the default model type key is 'type' instead of 'couchrest-type'. Simply updating your project will not work unless you migrate your data or set the configuration option in your initializers:

CouchRest::Model::Base.configure do |config|
  config.model_type_key = 'couchrest-type'

This is because CouchRest Model's are not couchrest specific and may be used in any other systems such as Javascript, the model type should reflect this. Also, we're all used to type being a reserved word in ActiveRecord.



$ sudo gem install couchrest_model


If you're using bundler, define a line similar to the following in your project's Gemfile:

gem 'couchrest_model'


CouchRest Model is configured to work out the box with no configuration as long as your CouchDB instance is running on the default port (5984) on localhost. The default name of the database is either the name of your application as provided by the Rails.application.class.to_s call (with /application removed) or just 'couchrest' if none is available.

The library will try to detect a configuration file at config/couchdb.yml from the Rails root or Dir.pwd. Here you can configuration your database connection in a Rails-like way:

  protocol: 'https'
  port: 443
  prefix: project
  suffix: test
  username: test
  password: user

Note that the name of the database is either just the prefix and suffix combined or the prefix plus any text you specifify using use_database method in your models with the suffix on the end.

The example config above for example would use a database called "project_test". Heres an example using the use_database call:

class Project < CouchRest::Model::Base
  use_database 'sample'

# The database object would be provided as:
Project.database     #=> ""



$ rails generate couchrest_model:config


$ rails generate model person --orm=couchrest_model

General Usage

require 'couchrest_model'

class Cat < CouchRest::Model::Base

  property :name,      String
  property :lives,     Integer, :default => 9

  property :nicknames, [String]


  view_by :name


@cat = => 'Felix', :nicknames => ['so cute', 'sweet kitty'])   # true

@cat['name']   # "Felix"

@cat.nicknames << 'getoffdamntable'

@cat =
@cat.update_attributes(:name => 'Felix', :random_text => 'feline') # false
@cat.random_text  # Raises error!



CouchRest Model now comes with a Gemfile to help with development. If you want to make changes to the code, download a copy then run:

bundle install

That should set everything up for rake spec to be run correctly. Update the couchrest_model.gemspec if your alterations use different gems.


The most complete documentation is the spec/ directory. To validate your CouchRest install, from the project root directory run bundle install to ensure all the development dependencies are available and then rspec spec or bundle exec rspec spec.

We will not accept pull requests to the project without sufficient tests.


Please post bugs, suggestions and patches to the bug tracker at

Follow us on Twitter:

Also, check