From: Chris White Date: 2011-08-01T03:30:25+09:00 Subject: Re: How to connect to and use Postgresql from Ruby On Jul 31, 2011, at 10:27 AM, Rannug Pong wrote: > Hello everyone. > > I have just started to learn Ruby, quite nice language, but I'm stuck on > connecting to the database (Postgresql) > > I have installed some ruby-pg and Ruby/DBI package for my Ubuntu system, > but then what? > > I'm having trouble with finding the correct/best documentation on how to > connect and how to perform queries to the database. > Can someone point me in the right dirrection here? > Simple example code could perhaps also be of value to get me started. > > Thank you all! > > -- > Posted via http://www.ruby-forum.com/. > 1) Install Postgres 2) Did a search for ruby postgres and found this: ruby-pg is now the official rubyforge project for the "postgres" ruby gem. See the project here: http://www.rubyforge.org/projects/ruby-pg 3) Go to the page in question, note that the project has been moved 4) Go to http://bitbucket.org/ged/ruby-pg/ 5) Read the install instructions, note the Ubuntu specific mention about the required libpq-dev package 6) sudo gem install pg (or no sudo if you want to do a home install) 7) Notice here's an examples directory: https://bitbucket.org/ged/ruby-pg/src/3d744d9776c3/sample/test1.rb 8) Start the postgres server 9) Switched to the postgres user (since postgres uses unix permissions by default) 10) Ran the code and got errors, realized it's because the sample code has not been updated to the latest version of the API 11) Screw this we're doing it live 12) Fix the code and put it on a gist (that's obviously not my password, and you might not need a password): https://gist.github.com/1117045 13) Run the code again and get the following output: datname datdba encoding datcollate datctype ... ... template1 10 6 C C ... template0 10 6 C C ... postgres 10 6 C C ... 14) Make note to self to fork that repository and push a fix 15) ??? 16) Profit! Regards, Chris White Twitter: http://www.twitter.com/cwgem