Moving rails project (with PostgreSQL) from local to Cloud9

rails
postgresql

#1

I tried to setup PostgreSQL in my cloud9 IDE as in

but when I tried to run, by using command “rails s -b $IP -p $PORT” it gives following error:

Puma caught this error: could not translate host name “<%= ENV[‘IP’] %>” to address: Name or service not known
(PG::ConnectionBad)
/usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in initialize' /usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:671:innew’
/usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in connect' /usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:217:ininitialize’
/usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in new' /usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:37:inpostgresql_connection’
/usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:721:in new_connection' /usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:765:incheckout_new_connection’
/usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:744:in try_to_checkout_new_connection' /usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:705:inacquire_connection’
/usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:501:in checkout' /usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:364:inconnection’
/usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:875:in retrieve_connection' /usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/connection_handling.rb:128:inretrieve_connection’
/usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/connection_handling.rb:91:in connection' /usr/local/rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/query_cache.rb:47:inblock in install_executor_hooks’
/usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:396:in instance_exec' /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:396:inblock in make_lambda’
/usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:169:in block (2 levels) in halting' /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:547:inblock (2 levels) in default_terminator’
/usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:546:in catch' /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:546:inblock in default_terminator’
/usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:170:in block in halting' /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:454:inblock in call’
/usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:454:in each' /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:454:incall’
/usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:101:in __run_callbacks__' /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:750:in_run_complete_callbacks’
/usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:90:in run_callbacks' /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/execution_wrapper.rb:107:incomplete!’
/usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/execution_wrapper.rb:64:in ensure in block in run!' /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/execution_wrapper.rb:64:inblock in run!’
/usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/execution_wrapper.rb:58:in tap' /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/execution_wrapper.rb:58:inrun!’
/usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.0/lib/action_dispatch/middleware/executor.rb:10:in call' /usr/local/rvm/gems/ruby-2.3.1/gems/actionpack-5.0.0/lib/action_dispatch/middleware/static.rb:136:incall’
/usr/local/rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/sendfile.rb:111:in call' /usr/local/rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/engine.rb:522:incall’
/usr/local/rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/configuration.rb:225:in call' /usr/local/rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/server.rb:569:inhandle_request’
/usr/local/rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/server.rb:406:in process_client' /usr/local/rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/server.rb:271:inblock in run’
/usr/local/rvm/gems/ruby-2.3.1/gems/puma-3.5.2/lib/puma/thread_pool.rb:116:in `block in spawn_thread’

My database.yml file looks like this:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: <%= ENV[‘USERNAME’] %>
password: <%= ENV[‘PASSWORD’] %>
host: <%= ENV[‘IP’] %>

development:
<<: *default
database: kineticapp_development

test:
<<: *default
database: kineticapp_test

production:
<<: *default
database: kineticapp_production

I would be very thankful if anybody can help me to fix this issue.

Thank you


#2

Is your Postgres service running? If not, start it with:

sudo service postgresql start


#3

Hello @BigChief45! Yes I have started the postgresql. It allows me to create database, migrated the files and seed. Only its not allowing me is to run the project when I give command “rails s -b $IP -p $PORT”. I am quite sure the problem is in database.yml file (host: <%= ENV[‘IP’] %>). I could not figure out how to mentioned host in right way in cloud9.


#4

Are you using any specific Postgres gem version?


#5

My gem file looks like this:

source 'https://rubygems.org
ruby ‘2.3.1’

gem ‘rails’, '~> 5.0.0’
gem 'pg’
gem ‘puma’, ‘~> 3.0’

gem ‘sass-rails’, '~> 5.0’
gem ‘uglifier’, '>= 1.3.0’
gem ‘coffee-rails’, '~> 4.2’
gem 'jquery-rails’
gem ‘turbolinks’, '~> 5’
gem ‘jbuilder’, ‘~> 2.5’
.
.
.
.
.


#6

According to the contents of the database.yml file you posted, I believe the issue could be in the indentation (or lack of) in your YAML file.

Have you checked that already? The format should look similar to this this:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5
  username: <%= ENV['USERNAME'] %>
  password: <%= ENV['PASSWORD'] %>
  host:     <%= ENV['IP'] %>

development:
  <<: *default
  database: app_development

test:
  <<: *default
  database: app_test

production:
  <<: *default
  database: app_production

If you are using tabs instead of spaces, that might cause some problems as well I think.