Install and run a simple ruby on rails application in windows xp (Netbeans & Instant rails)


Few days ago i made a blog post regarding ruby on rails installation in Linux machine . But some of my friends told me to write a post regarding ruby on rails installation in windows machine. So here is what you need to  do, though I found it little difficult to setup ruby on rails environment in windows  :(

To install ROR in windows xp what you need is listed below

  • Instant Rails
  • Netbeans IDE

OR

  • cRuby Interpreter(C based ruby) or jRuby interpreter (java based ruby)
  • Webrick or Mongrel or Glassfish or Apache server.
  • Database (PosgreSQL, MySQL, Sqlite, Microsoft SQL server …..)

I like cRuby interpreter and mysql as i’m much familiar with C and MySQL. Ruby on Rails supports large number of databases and one of its main feature is database abstraction (Active Record) which allows one to change full database server anytime he/she wants and you don’t have to change a single line of code in the main application.

Anyway, You can use Instant rails (cRuby & MySQL) for installing Ruby on Rails in windows and Netbeans IDE 6.5 for developing Ruby on Rails application. Netbeans is a standalone IDE and it already comes up with jruby interpreter by default.

So install Instant rails and start mysql service, you don’t need to start apache service as we’ll use webrick server (default) for ROR application. Now install and start netbeans IDE.

Now you need to change ruby interpreter from Tools-> Options-> Ruby now browse ruby.exe file from Instant rails directory (where it was installed, most often the directory is, C:/instant rails/ruby/bin/ruby.exe)

Now in the Netbeans window open a new project, select ruby from category then select Ruby on rails Application from projects. Click on next button, type project name and open that project.

Now run the project from Netbeans window, It will automatically open the project in your default browser (if not, type localhost:3000 in the url of browser). There is a rails console in the Instant rails window, one can use that console to test or manage project too.

Ruby is on rails now. Installation part complete.

Ok, Now i’m considering the fact that ROR(Instant rails for windows) & netbeans IDE installed in your pc, follow the steps below to develop a simple rails application (an AMD tool) using scaffold method.

Step 1: start Instant rails (cruby and mysql) and Netbeans IDE

Step 2: In netbeans window open a new Ruby on rails project. Bunch of files will be created in the project folder.

Step 3: Change mysql database name, username and password (if you want different db name, user and password)

Step 4: Now create the database from netbeans. To do this, right click on the project folder select Run rake task->db->create. This will create the database in mysql.

Step 5: Again right click on the project folder, click generate. Select scaffold from the dropdown, type model name in a singular form (such as post) now in the action field type field names: field type that you want in the application you are developing. In my case its (title and body), so type title:string body:text in the action field. Now click OK.

This will generate necessary files with default code in controller, view, database migration and other necessary folders. In Database migrate->migrate folder, you will notice a file which contains info to generate database tables and fields in the database. Now, to create table with specified fields in the database we need to migrate database to current version.

Step 6: Right click on the project, select migrate database->To current version. This will create db table with specified fields.

Step 7: You are done. Now run the project from netbeans and type localhost:3000/posts (posts is the controller name) in the url of any explorer. you will see your application running.

VOILA!!

, , ,

  1. #1 by Matt Ricardo - May 9th, 2009 at 11:49

    Good job. This post really helped me. Why don’t you update your blog regularly!

    Can you help me a little? Please check your mail…

(will not be published)
  1. No trackbacks yet.