Postgres Error On Heroku

Recently, I ran into an error while deploying an application(redmine to be specific) on heroku.
I followed all steps listed on the wiki page, remove the required files from gitignore etc but when I did git push, I kept on getting the error:

Please configure your config/database.yml first
remote: rake aborted!
remote: URI::InvalidURIError: bad URI(is not URI?): ://user:pass@

Since Heroku generates database.yml file itself, I had no clue what to do.
So in the gemfile, I deleted the following block:
# database_file = File.join(File.dirname(__FILE__), "config/database.yml")
# if File.exist?(database_file)
# database_config = YAML::load(
# adapters = {|c| c['adapter']}.compact.uniq
# if adapters.any?
# adapters.each do |adapter|
# case adapter
# when 'mysql2'
# gem "mysql2", "~> 0.3.11", :platforms => [:mri, :mingw, :x64_mingw]
# gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
# when 'mysql'
# gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
# when /postgresql/
# gem "pg", "~> 0.17.1", :platforms => [:mri, :mingw, :x64_mingw]
# gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby
# when /sqlite3/
# gem "sqlite3", :platforms => [:mri, :mingw, :x64_mingw]
# gem "jdbc-sqlite3", "< 3.8", :platforms => :jruby
# gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
# when /sqlserver/
# gem "tiny_tds", "~> 0.6.2", :platforms => [:mri, :mingw, :x64_mingw]
# gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw, :x64_mingw]
# else
# warn("Unknown database adapter `#{adapter}` found in config/database.yml, use Gemfile.local to load your own database gems")
# end
# end
# else
# warn("No adapter found in config/database.yml, please configure it first")
# end
# else
# warn("Please configure your config/database.yml first")
# end

and added

group :production do
# gems specifically for Heroku go here
gem "pg", ">= 0.11.0"

Also in config/environments/production.rb,I added the following line:

config.assets.initialize_on_precompile = false

Once I pushed, the above error went away but I got the following error:

Running: rake assets:precompile
remote: rake aborted!
remote: PG::ConnectionBad: could not connect to server: Connection refused
remote: Is the server running on host "" and accepting

The problem here was I didn’t pre-provision my database before pushing to heroku.

So solve this, one can run the command:

heroku addons:create heroku-postgresql

So know about the issue, one can always use:

heroku config

Before running the command, heroku config, returned DATABASE_URL as blank and that was the issue.

Hope it helps !!

Resetting a Database in Heroku application

Recently I faced an issue when  I wanted to delete an existing database in an application deployed in heroku and create a new one.

I tried using

heroku run rake db:drop


I got an error saying “USER does not have connect privilidges”

The way to solve it is

heroku pg:psql

This logs in to your database and then type:

drop schema public cascade;
create schema public;

After this exit the prompt and type:

heroku rake db:migrate:reset

Hope it helps.


Install apache web server and passenger on Ubuntu 11.04(Natty)

I just Installed apache and passenger on Ubuntu 11.04 to run and deploy my ruby on rails applications Passenger is a gem and can work with apache as well as nginx…

The reason for choosing apache is that its an industry standard.

Also one thing I did with apache was created virtual hosts and ran my apps on local machine with domains like

In this post I will list the steps I followed in order to setup apache web server and passenger.

Here is my stack:

  •  Ubuntu 11.04
  •  ruby 1.9.2 via rvm
  •  rubygems 1.8.10

I will be using rails 3.1.10(lastest this morning).!!

So lets start !!

  • Install rvm

To install rvm just type the following in the terminal(ctrl+alt+t)

 user$ bash < <(curl -s )

You can find more information about rvm on Here

  • Install ruby via rvm

Once rvm is installed you can install the latest or desired version of ruby by typing the following in terminal

rvm install 1.9.2

This will install ruby 1.9.2 on your system.

More information on how to make it your default ruby is available on here

  • Install rails.

just need to do

gem install rails

  • Install passenger

just do

gem install passenger

  • Install apache web server.

To install apache web server type:

sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev
  • Install passenger apache module.

Once this is done, we must install passenger , an apache module thats hepls us to rub rails apps on apache.

sudo passenger-install-apache2-module
  • Configure.

Finally everything is done.

When you run the passenger apache module, there would be some instructions that installer will give you.

The last thing it will tell is to paste some text in apache configuration file

The configuration file is located at /etc/apache2/apache2.conf

Now once this is done, we are ready to deploy.

This has a lot of information about deploying.

In my next post, I will show how to start rails apps on local machine with apache.

Hope it helps.!

Segmentation Fault while doing bundle install

I recently encountered this error of segmentation fault while doing bundle install in one of my rails application.

After a bit of googling I found out its an issue with ruby 1.9.3.

Here is the solution:


rvm pkg install iconv
 rvm pkg install openssl
 rvm reinstall 1.9.3 --with-openssl-dir=~/.rvm/usr --with-iconv-dir=~/.rvm/usr


Rails and attr_*

There is a small gotcha in rails attr_accessible method in ruby.

  • If there are no attr_accessible attributes on a model it’s open, any attribute can be written with .update_attributes() or a similar mass-assignment function.
  • If there is even one attr_accessible the model is closed except for those attributes defined to be attr_accessible.

So there is an implicit toggle involved in attr_accessible as well as the actual desired functionality of allowing an attribute to be mass-assigned

Creating virtual hosts in apache in local machine

In this post I show how to create virtual hosts on apache and run multiple rails apps on your local machine with names like

In the previous post I had shown how to deploy rails apps on local machine with apache web server

My software stack:

  • Ubuntu 11.04
  • ruby 1.9.2 p290.
  • Rails 3.1.10
  • rubygems 1.8.10

Lets start!

First we have to enable virtual aliases on the Apache S

sudo a2enmod vhost_alias

Now I assume that the rails app is at the location:



We first create a virtual configuration file:

Tyep the following in terminal:

sudo gedit /etc/apache2/sites-available/mydomain

Copy the following settings to your file:


<VirtualHost *:80>

DocumentRoot /home/username/Desktop/rails_apps/my_rails_app/public
<Directory />
Options FollowSymLinks
AllowOverride All
<Directory //home/username/Desktop/rails_apps/my_rails_app/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

<Directory “/usr/lib/cgi-bin”>

AllowOverride None

Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch

Order allow,deny

Allow from all



ErrorLog ${APACHE_LOG_DIR}/error.log


# Possible values include: debug, info, notice, warn, error, crit,

# alert, emerg.

LogLevel warn


CustomLog ${APACHE_LOG_DIR}/access.log combined


Alias /doc/ “/usr/share/doc/”

<Directory “/usr/share/doc/”>

Options Indexes MultiViews FollowSymLinks

AllowOverride None

Order deny,allow

Deny from all

Allow from ::1/128



Important to note here is to change ServerName as per your convinince and Directory to your public of rails app.

Once this is done,

type the following to open the hosts file:

 sudo gedit /etc/hosts


In this file, copy the following code:


replace domain name with your desired name.

This is what you will use in browser to access the page

Activate your domain and reload the Apache Server to enable settings
Enable the site

a2ensite domain-name


Reload Apache2

/etc/init.d/apache2 reload


Finally test your app by typing and see the magic !!!



Deploying rails app with apache locally

In this post I am going to show how to make apache the server for all ruby on rails application on local machine.

In the previous post I had shown how to install apache web server ad configure it.

My software stack:

  • Ubuntu 11.04
  • ruby 1.9.2 p290.
  • Rails 3.1.10
  • rubygems 1.8.10

Lets start!

I assume that you have a rails app in the following path:


It is important to note that apache serves all local request via www directory in /var.


So the first step is to create a symbolic link:

ln -s /home/username/Desktop/rails_apps/my_rails_app/public /var/www/my_rails_app

Note that sym link should be to your appls publc folder.

Now edit the following file(you can coly paste the code)

sudo gedit /etc/apache2/sites-available/default

In this file, append the follwing line:

RailsBaseURI /my_rails_app
RailsEnv development #(if you want to run on development mode default is production)

Restart apache using

sudo /etc/init.d/apache2 restart

 Now on you browser when you type
 the app should fire up !

Hurray you have done it !

————————————–warning for ruby 1.9.2p290————————————————

When I fired up my app, I got an error

Can’t convert nil to hash,

This is phsyc problem and to solve this, add the following to boot.rb

(this issue existed when I did used it )

require ‘yaml’

YAML::ENGINE.yamler = ‘syck’