Just start with rails and Linux a few days a go…
I want to deploy to heroku and one of there best practice is to user postgresql in local environment too anyway… I followed one of there tutorials and created a sample application
the pg gem installed. bundle install works ok. rake db:migrate works and created the table for my application. but… when i try to run my rails page it gives this error:
ActiveRecord::ConnectionNotEstablished
This is the end of the full trace:
> activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `retrieve_connection'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
activerecord (3.2.3) lib/active_record/query_cache.rb:67:in `rescue in call'
activerecord (3.2.3) lib/active_record/query_cache.rb:61:in `call'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `_run__4423031206660944571__call__1711406629982304701__callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
i am using pgadmin 3 to see my db. i created a user named schaller which is the same as my user in Ubuntu
my database.yml file:
development:
adapter: postgresql
database: rails
encoding: unicode
username: schaller
password: password123
host: localhost
pool: 5
what else can i check in order for rails to connect to postgres?
edit:
error when starting the rails server in netbeans on webrick
Started GET “/gangs/” for 127.0.0.1 at 2012-09-13 23:12:31 +0300
ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished):
activerecord (3.2.3) lib/active_record/connection_adapters/abstract /connection_pool.rb:398:inretrieve_connection'retrieve_connection’
activerecord (3.2.3) lib/active_record/connection_adapters/abstract /connection_specification.rb:168:in
activerecord (3.2.3) lib/active_record/connection_adapters/abstract /connection_specification.rb:142:inconnection'rescue in call’
activerecord (3.2.3) lib/active_record/query_cache.rb:67:in
…
edit the main stuff in my gem file:
gem 'rails', '3.2.3'
gem 'pg'
gem 'thin'
edit:
adding logs for the postgresql connections
[local]
2012-09-15 18:05:35 IDT LOG: connection received: host=127.0.0.1 port=44038
2012-09-15 18:05:35 IDT LOG: connection authorized: user=schaller database=postgres
2012-09-15 18:05:35 IDT LOG: connection received: host=127.0.0.1 port=44039
2012-09-15 18:05:35 IDT LOG: connection authorized: user=schaller database=rails
2012-09-15 18:07:26 IDT LOG: connection received: host=127.0.0.1 port=44048
2012-09-15 18:07:26 IDT LOG: connection authorized: user=schaller database=rails
anyway i see logs being written when i connect with pgadmin 3 and when i run the command, ‘rake db:migrate’ but not when i run my rails app…
thanks
OK so its been a few days.. i read all answers and comments again because i really needed a solution anyway! the comment left by @Muhammad Sannan did the trick. i am new to rails so i didn’t know what an adapter is.. but after a quick google search i ran this command:
and that did the trick 🙂
everything is working now. i just don’t understand how db:migrate worked without this adapter..