Wednesday, August 19, 2009

Ruby - Rails - PostgreSQL Issues

I encountered a couple of issues with the development stack. Luckily, I was able to solve them since they were documented on the web. By way of review, my development environment is as follows:
Operating System: Windows XP
Ruby: 1.8.6
Rails: 2.3.3
PostgreSQL: 8.4.0

A) The first error occured when starting WEBrick server. A pop up message displayed:
ruby.exe Ordinal Not Found
The ordinal 284 could not be located in the dynamic link library SSLEAY32.DLL

Searching the web led me to this post at Stackoverflow. My solution was to:

1) Rename libeay32.dll and ssleay32.dll in both ruby\bin folder and posgresql\lib folder to old_libeay32.dll and old_ssleay32.dll respectively. This way I don't lose these dlls in case my fix doesn't work.

2) Install Visual C++ 2008 Redistributables which can be obtained from Microsoft site. This is needed prior to installing OpenSSL below.

3) Install the latest OpenSSL from Shining Light Productions. I used "Win32 OpenSSL v0.9.8k Light".

4) Copy libeay32.dll and ssleay32.dll from OpenSSL folder to h ruby\bin and posgresql\lib folder.

5) Restart WEBrick server and the error should be gone.


B) The second error occured in the browser when Rails tried to connect to PostgreSQL. I tried to migrate a model using rake db:migrate. An error displayed:
Rake aborted!
undefined method 'quote_indent' for PGconn:class

Searching the web led me to this post at HighDot Forums. My solution was to:

1) Open Rails file config/initializers/new_rails_defaults.rb

2) Add the following code at the end of the file:


# Postgres "quote_indent for PGconn:class" fix from http://www.highdots.com/forums/ruby-rails-talk/quote_ident-283323.html
def PGconn.quote_ident(name)
%("#{name}")
end


After that, I did not experience any other issues with the development environment.

Sunday, August 16, 2009

Ruby & Ruby On Rails Installation Complete


While there are numerous write ups on this process (just Google "install ruby on rails"), I thought I'd include a brief description for blog completeness

1) Go to Ruby on Rails download page to Download and install Ruby. Enable RubyGems option. I used Windows 1.8.6-27 Release Candidate 2.

2) When finish, open a command prompt and install rails 2.3.3 :
>gem install rails

3) Install PostgrSQL driver:
>gem install postgres-pr

4) Create sample Rails application:
>rails c:\temp\railstest

That's all there is to it. For a quick tutorial, I suggest going to http://guides.rubyonrails.org/ .

Tuesday, August 11, 2009

PostgreSQL 8.4.0 Setup Complete




The Installation process was very straightforward and provided no surprises. Simply go to www.postgreSQL.org and download release 8.4. Run the installer and it should be very easy. A windows service called "PostgreSQL Server 8.4" will be created and can be verified by checking Control Panel, Administrative Tools, Services. If it does not start automatically, simply right click on it and select Start.



Once the database is running, connect to it and create a 'tradingbot' database.


C:\temp>psql -U postgres
Password for user postgres:
psql (8.4.0)
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.

postgres=# create database tradebot;
CREATE DATABASE
postgres=# \l
List of databases
Name | Owner | Encoding | Collation | Ctype
| Access privileges
-----------+----------+----------+----------------------------+-----------------
-----------+-----------------------
postgres | postgres | UTF8 | English_United States.1252 | English_United States.1252 |
template0 | postgres | UTF8 | English_United States.1252 | English_United States.1252 | =c/postgres

: postgres=CTc/postgres
template1 | postgres | UTF8 | English_United States.1252 | English_United States.1252 | =c/postgres

: postgres=CTc/postgres
tradebot | postgres | UTF8 | English_United States.1252 | English_United States.1252 |
(4 rows)

postgres=# create user master with password 'blaster';
CREATE ROLE
postgres=# grant all on database tradebot to master;
GRANT
postgres=# \q

Line 1: Connect to default database
Line 9: Create database "tradebot"
Line 27: Create new user called "master"
Line 29: Grant privileges to "master"

Next step is to log into the new database and create a test table.


C:\temp>psql -d tradebot -U master
Password for user master:
psql (8.4.0)
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.

tradebot=>\d
No relations found.
tradebot=> create table tester (id varchar(10) not null);
CREATE TABLE
tradebot=> \d
List of relations
Schema | Name | Type | Owner
--------+--------+-------+--------
public | tester | table | master
(1 row)


tradebot=> \d tester
Table "public.tester"
Column | Type | Modifiers
--------+-----------------------+-----------
id | character varying(10) | not null


tradebot=>

Line 1: Connect to tradebot database
Line 9: Get listing of all tables in the database. None returned because database is empty.
Line 11: Create "tester" table
Line 13: Get listing of all tables in the database. "Tester" table appears.
Line 21: Get "tester" table information

Saturday, August 8, 2009

Specifications: Watcher

The Watcher Application specifications document is now complete. I have published it using Google docs rather than posting in blog format because it will be easier to make changes over time. As with all software specifications, this is a living document and will be updated often as needed. I will keep a revision history at the bottom of the document to track any major changes.