2
I have installed ruby 1.9.3-p327, and my databse is postgres.I modified the database.yml page also..as:evelopment:

adapter: postgresql database: db_pchamara username: db_test_user password: password host: 192.168.1.101 pool: 5

test: adapter: postgresql database: db_pchamara.test username: db_test_user password: password host: 192.168.1.101 pool: 5

production: adapter: postgresql database: db_pchamara username: db_test_user password: password host: 192.168.1.101 pool: 5 .but I am facing the problem that when I run rails server it shows the following error:It is not ocnnecting to postgre db..

but if run the ruby file, it gets data from db: help me with this,.....

ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished):
  activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
  activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
  activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
  activerecord (3.2.9) lib/active_record/query_cache.rb:67:in `rescue in call'
  activerecord (3.2.9) lib/active_record/query_cache.rb:61:in `call'
  activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `_run__241814793__call__597619238__callbacks'
  activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.9) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.9) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.9) lib/rails/rack/logger.rb:32:in `call_app'
  railties (3.2.9) lib/rails/rack/logger.rb:16:in `block in call'
  activesupport (3.2.9) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.9) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.9) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/static.rb:62:in `call'
  railties (3.2.9) lib/rails/engine.rb:479:in `call'
  railties (3.2.9) lib/rails/application.rb:223:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.9) lib/rails/rack/log_tailer.rb:17:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
  /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
  /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'


  Rendered /usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.4ms)
  Rendered /usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.9ms)
  Rendered /usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (9.6ms)



This is my gemfile.lock

Gems included by the bundle:
  * actionmailer (3.2.9)
  * actionpack (3.2.9)
  * activemodel (3.2.9)
  * activerecord (3.2.9)
  * activeresource (3.2.9)
  * activesupport (3.2.9)
  * arel (3.0.2)
  * builder (3.0.4)
  * bundler (1.2.3)
  * coffee-rails (3.2.2)
  * coffee-script (2.2.0)
  * coffee-script-source (1.4.0)
  * erubis (2.7.0)
  * execjs (1.4.0)
  * hike (1.2.1)
  * i18n (0.6.1)
  * journey (1.0.4)
  * jquery-rails (2.1.4)
  * json (1.7.5)
  * mail (2.4.4)
  * mime-types (1.19)
  * multi_json (1.4.0)
  * pg (0.14.1)
  * polyglot (0.3.3)
  * rack (1.4.1)
  * rack-cache (1.2)
  * rack-ssl (1.3.2)
  * rack-test (0.6.2)
  * rails (3.2.9)
  * railties (3.2.9)
  * rake (10.0.2)
  * rdoc (3.12)
  * sass (3.2.3)
  * sass-rails (3.2.5)
  * sprockets (2.2.2)
  * thor (0.16.0)
  * tilt (1.3.3)
  * treetop (1.4.12)
  * tzinfo (0.3.35)
  * uglifier (1.3.0)
Pavan Kumar
  • 1,735
  • 2
  • 28
  • 47
  • 4
    Instructions for compiling with OpenSSL using RVM are available at rvm.io/packages/openssl –  Dec 04 '12 at 13:14
  • I suspect the problem has nothing to do with SSL (I could be wrong). I'll bet that in your development environment, your database.yml is configured to use SQLLite and possibly your Gemfile references sqllite for development. You should use bundler (not `gem install`) to manage the gem dependencies of your rails application. If you haven't been doing this, then you may have a confused application. – Tom Harrison Dec 04 '12 at 13:29
  • This may be a problem. You are using postgressql database but installing sqlite3 by bundler. Morever your database.yml should be having same settings for database as of what you are using and that same should be in your gemfile for bundler. Update it and then see what happens. – sjain Dec 04 '12 at 13:57
  • http://stackoverflow.com/questions/12882190/unable-to-resolve-ruby-error-missing-psych/12882906#12882906 Check that out to get around your "missing Psych" error. – Eugene Dec 04 '12 at 14:47
  • Can you copy/paste the contents of your Gemfile? –  Dec 05 '12 at 21:22
  • hey that gem problem was solved.. i just reinstalled everything.. but now the problem is if i made changes to database.yml to connect to postgresql, and then if i run the server, it shws ACTIVE CONNECTION NOT ESTABLISHED.. I installed pg gem also..but of no use – Pavan Kumar Dec 06 '12 at 13:26
  • @Aruna I have added my gemfile to the above problem. please go through that...... – Pavan Kumar Dec 07 '12 at 05:34

2 Answers2

2

Check your Gemfile which is located in the root of your application directory.

remove gem 'sqlite' and add gem 'pg' then save. run bundle install

the best way to install gems is to add them to the gem file and run bundle install. running "gem install -" is not recommended

you will also need to modify your database.yml which is located in the config folder and make the necessary adjustments to run pg.

Richard Lau
  • 696
  • 9
  • 22
  • everything was done.. but i did mistake somewhere.. the server is not connecting to database – Pavan Kumar Dec 06 '12 at 13:54
  • what are the errors you are getting? You can download Navicat to make sure your database was created. – Richard Lau Dec 06 '12 at 20:12
  • my database in on another ip.. I have to work on remote machine.. so i cant download everything yaar – Pavan Kumar Dec 07 '12 at 06:01
  • if it is on another ip. did you make sure the ip address is correct? Also is this in production already? you might need to add pg to the production part of the gem file. – Richard Lau Dec 07 '12 at 18:35
  • How to add pg to the production part?? are u asking me about the production part in database.yml file?? In that file everything I had given what ever it asks.. – Pavan Kumar Dec 08 '12 at 06:04
1

If u are facing this type of errors u have to check three files..

1.database.yml 2. pg_hba.conf in postgresql lib. 3. if u are working on the remote machine we have to include our host ip to the database.yml file also...

while creating the project use his command to know to server that u are going to use postgresql..

'rails new demo --database=postgresql'

then only the pg gem file will get load to bundle..

Coming to pg_hba.conf file edit as trust where it is md5. it will be near your ip address.

md5- requires a password to connect to db trust- dont asks a password

Be sure that your database.yml file is correct

Pavan Kumar
  • 1,735
  • 2
  • 28
  • 47