CouchRest Rails Setup - Blank username/password issues

Setting a blank username/password is not the same as not setting a username/password

If you are using CouchRest in your Rails project and locally you don't want to set a username and password for your couchdb install then bare in mind that the following are not the same;

CouchRest::Model::Base.configure do |config|
    config.connection = {
        :protocol => 'http',
        :host     => '127.0.0.1',
        :port     => 5984,
        :prefix   => '',
        :suffix   => Rails.env,
        :join     => '_'
    }
  end

The code above has no username and password set, so it will not try and speak to CouchDB with any credentials.

The code below *has* a username and password set but they are both blank, so it will try and speak to CouchDB with the username and password both being set to an empty string, this will result in a 401 Not authorised error.

CouchRest::Model::Base.configure do |config|
    config.connection = {
        :protocol => 'http',
        :host     => '127.0.0.1',
        :port     => 5984,
        :prefix   => '',
        :suffix   => Rails.env,
        :join     => '_',
        :username => '',
        :password => ''
    }
  end

This isn't particularly unique to CouchRest at all but it tripped me up earlier so I figured I would share :-)

Recent posts View all

Ruby

How to install a beta version of Rails

This article will show you how using the gem command you can install beta versions of Rails

Ruby

The Welcome to Rails image is more inclusive

When playing with the new beta of Rails I noticed a more inclusive image