Installing Rails on Windows

In order to have a fully working development environment, you can use your PC. You will need to install:

Ruby – the language Ruby
Gems – the plug-in manager for Ruby
Scite or FreeRIDE – IDE for Ruby
MySQL – the database
MySQL query builder / MySQL admin tools – GUI to create databases, add users and create tables Rails Framework

Here i am going to give you the detail information on how to install ruby on rail framework, and i am assuming that you already installed the Wamp/MYSQL in you system. The WAMP/MYSQL is must to run the ruby on rail framework.

1. Installing Ruby

This is easy. Just get the latest One-click Installer for Windows (http://rubyinstaller.rubyforge.org/wiki/wiki.pl)(currently 1.8.2-15). Installation is simple, and indeed one-click. Once the installation is complete, check that path to ruby\bin directory is in your PATH variable (Run “cmd”, then type “path” at the prompt and check that the path is there.

The great thing about the one-click installer is that it comes with Ruby Gems, Scite and FreeRIDE preinstalled. The thing to watch out for is that one-click installer does not have the very latest version of Ruby, so when you are reading Ruby Docs, make sure you know which version of Ruby you have (run “ruby -v” in the command prompt).

2. Installing Rails

2.1. Go into the ruby bin directory and run this command from the command prompt:
gem install rails –include-dependencies

(If this command gives you an error, you do not have the latest version of gems installed. Run “gem -v”, it should be 0.8.10. If it’s an earlier version, I recommend to reinstall the newest package – see beginning of the tutorial).

This command will install rails 1.0 and RDoc documentation for it. It should take up to 5-10 minutes, so do not worry when for a couple of minutes you just see a message “Updating Gem source index for: http://gems.rubyforge.org/” – there is no progress bar or any other indication of activity, but it is doing the work.

At the end you should see something like this:

2.2. After that, create a directory for all of your projects. I just have one in the ruby directory. Go into this directory by using the “cd c:\ruby/myprojectsdir” and run

rails firstproject

You should see something similar:

2.3. Finally, “cd firstproject” and run

ruby script/server

This will run the file “server” (no extension) in the script subdirectory of “firstproject directory”, which will in turn run the Rails built-in web server WEBrick. Test the web server by opening the following address in your browser:

http://127.0.0.1:3000/

You should see the following pic:

One of the drawbacks of having a Ruby-based web server is that WEBrick needs to run in its separate command prompt window, so you should be careful not to close the window down incidentally, or you will need to restart the web server.

Congratulations! YOU ARE ALMOST DONE!

Now you have to create a project in follownig way,

3. Rails in action

3.1. Now that the database model was prepared, we need to switch it on for our project. Go into your rails project subdirectory (you remember where you created it, right?). In the “config” subfolder you will find file database.yml. Open it and find the “development” section. In it, change database name to “firstproject”, username to “rails”, password to rails user password. Leave socket unchanged. Here is how it will look like:

development:
dapter: mysql
database: firstproject
username: mysql_admin
password: mysql_pass
socket: /path/to/your/mysql.sock

In order for those changes to work, you will need to restart the WEBrick server. Close the WEBrick window and run the server command again:

ruby script/server

3.2. You have the database schema defined and you configured Rails to access your database. Now, what we need is to create the class called “Story”. The easiest way to go is to create a scaffold, which is basically a default script to work with the standard database operations under the acronym of CRUD (Create Read Update Delete or in SQL terms: INSERT, SELECT, UPDATE and DELETE). To do this, again go to your script’s directory and run this command:

ruby script\generate scaffold Story

Make sure that you use the capital “S” – this is actually a Ruby rule that you need to follow – class names need to be capitalized. So, this is where the magic happens – you do not need to define the class in Ruby the “hard-way”. You define the class variables (so-called states) only once – in the database, and then those variables are automatically recognized by Rails and a standard CRUD framework is applied, which you can replace with your own code as you go.

3.3. Finally, check that everything works by going to this link: http://127.0.0.1:3000/stories/

For fun, try creating, updating and deleting records and see how the table records are automatically updated in the MySQL CC or Query Browser.

One of the drawbacks of having a Ruby-based web server is that WEBrick needs to run in its separate command prompt window, so you should be careful not to close the window down incidentally, or you will need to restart the web server.

Congratulations! YOU ARE ALMOST DONE!
Original Post from :
http://allaboutruby.wordpress.com

Advertisements

1 Comment

  1. June 26, 2009 at 5:48 pm

    […] In order to have a fully working development environment, you can use your PC. You will need to install: Ruby – the language Ruby Gems – the plug-in manager for Ruby Scite or FreeRIDE – IDE for Ruby MySQL – the database MySQL query builder / MySQL admin tools – GUI to create databases, add users and create tables Rails Framework Here i am going to give you the detail information on how to install ruby on rail framework, and i am using that you already installed the Wamp/MYSQL in you syst See the rest here: Installing Rails on Windows […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: