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

Web DevProductivity

Keeping on top of website updates

Learn what website updates are, what they entail, why they are important, and how we can help

Freelancing

Getting the most out of your agency

Here are some tips based on years of working with, for, and as an agency on how to get the most out of any work you do.