Showing posts with label MySQL. Show all posts
Showing posts with label MySQL. Show all posts

Saturday, August 15, 2009

Ubuntu 9.04 : How to Install Ruby on Rails 2.3.3 [15th August 2009]

CCH : These are the steps that I took to install Ruby on Rails to an IBM Thinkpad with 1G RAM and a 75G Hard Disk and installed with Ubuntu 9.04.

Ruby installation

Firstly, I clicked Applications/Accessories/Terminal to launch the Terminal and typed the following command to update the repositories.
sudo apt-get update
next, to upgrade the system :-

sudo apt-get dist-upgrade
The installation took afew minutes and also required approximately 100 MB disk space.
On succesful updating, I started to install Rails.
sudo apt-get install ruby ri rdoc irb libopenssl-ruby ruby-dev

Note : Rails prerequisites include :-
ruby = An interpreter of object-oriented scripting language Ruby
ri = Ruby Interactive reference
rdoc = Generate documentation from ruby source files
irb = Interactive Ruby

Ruby Gem installation

Next, I started to install the Ruby gem package manager by firstly downloading ad the latest Ruby gems .35 via the following link.
http://rubyforge.org/projects/rubygems/

Download and extract the files.
tar xvzf rubygems-1.3.5.tgz
cd rubygems-1.3.5
sudo ruby setup.rb

I then deleted the .tgz file and rubygems directory.
cd ..
rm -r rubygems-1.3.5 rubygems-1.3.5.tgz

Next, I set out to create a set of simlinks. Otherwise it will be a tedious task to type commands with the version (1.8). For an example if we need to call the gem command we’ve to type gem1.8.

sudo ln -s /usr/bin/gem1.8 /usr/local/bin/gem
sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby
sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc
sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri
sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb

Rails Installation

I then installed Rails using gem.
sudo gem install rails

Server Installation

FYI, Rails by default comes with the WEBrick server. But like most Rails developers, I prefer the Mongrel server and typed the following command to install Mongrel server as well as passenger 2.2.4 and capistrano 2.5.8 for deployemnt purposes

sudo gem install mongrel passenger capistrano
TIP : If you got any error while installing the Mongrel server, install the ruby-dev / ruby1.8-dev and try again.
sudo apt-get install ruby-dev
Database Installation
Rails 2.3 shipped with SQLite3 as it’s default database instead of MySQL. You can install SQLite3 libraries by following commands.
sudo apt-get install sqlite3 swig libsqlite3-ruby libsqlite3-dev
sudo gem install sqlite3-ruby
Since I prefer MySQL,
sudo apt-get install mysql-client libmysqlclient15-dev
sudo gem install mysql

Create Ruby on Rails App

With no error mesages, I proceeded to create a new Ruby on Rail application by following command :-

rails test_app
As I needed MySQL support, I typed :

rails test-app -d mysql

Run the app

cd test_app
script/server
I then point FireFox to http://localhost:3000
and bingo I succeeded in launching my first RoR apps on Ubuntu :-)

Thursday, October 11, 2007

Advanced Rails : Moving an Existing Database to a Rails Application

Assuming that you have an existing application that you wish to rewrite in Rails, how would you prepare your database schema so that you can take advantage of the magick of db:migrate ?

Well, I had to do exactly that when I decided to rewrite an existing 200+tables CRM solution into e-CRM, a Rails application. This is what I did :-

a) Pluralize all the table names

Tip: One legacy table was named customer. To pluralize it to customers whilst retaing the data, I use CREATE TABLE customers SELECT * FROM customer for MySQL

b) Add an id field (auto-increment, integer) to every table

c) Add created_at, updated_at in every table to take advantage of Rails automatic updating of these fields without a single line of code

d) Added another magic column ie lock_version (must default to 0) to invoke optimistic locking

e) To support a belongs_to relationship, add belongs_to_tablename

f) Create a schema_info table with just 1 field ie Version, Integer and add a single record with the value=1

g) Use Rake db:schema:dump to create a schema.rb based on the underlying database schema . See following snapshot of Radrails in action
h) Create an empty migration file say 001_migrate2mysql and copy the contents to the Self.Up Method as shown in the Radrails snapshot as follows :-

That's it !
Updated on 4th November, 2007.

Welcome to Rails.. Rails... Rails !

In 1995, I started the popular Clipper...Clipper... Clipper website (no blogs then) which was very popular and linked by virtually every Clipper-related site. When I switched to Windows via Delphi in 1997, I started the Delphi... Delphi... Delphi site. In June 2007, I discovered Ruby on Rails and no prize for guessing what I am gonna name this blog. which I started on 2nd October 2007.

As at 10th June 2010, we have 13,364 unique visitors from more than 84 countries such as Angola, Andorra, Argentina, Australia, Austria, Algeria,Barbados, Bosnia and Herzogovina, Belgium, Brazil, Bulgaria, Bangladesh, Belarus, Bolivia, Chile, Cambodia, Cape Vede, Canada, China, Colombia, Costa Rica, Croatia, Cyprus, Czech Republic, Denmark, Egypt, Estonia, Finland, France, Guadeloupe, Guatemala, Germany, Greece, Hong Kong, Hungary, India, Indonesia, Ireland, Israel, Italy, Japan, Kenya, Korea, Lithuania, Latvia, Malaysia, Mexico, Macao, Netherlands, Nepal, Norway, New Zealand, Oman, Panama, Peru, Poland, Portugal,Paraguay , Philippines, Romania, Russian Federation, Saudi Arabia, Singapore, Spain, Slovakia, Slovenia, Serbia, South Korea, Slovenia, South Africa, Spain, Switzerland, Sri Lanka, Sweden, Taiwan, Thailand, Turkey, United Arab Emirates, Ukraine, USA, UK, Venezuela, Vietnam

CCH
10th June 2010, 19:42