Sunday, August 29, 2010

Creating your first Ruby program!

Create a simple file and type

puts "Rails World"

save the file in .rb extension (example: rails.rb).

On the command line, go to the folder containing your "rails.rb" and run

>> ruby rails.rb

Congratulations, you created your first rails application.

Installing Ruby on Windows

After installing cygwin, next step is to install Ruby on your computer. For installing ruby refer to rubyonrails.org. Follow the simple steps specified there. For installing latest Rails:
gem install rails --pre

Now, it will be easy to install bundler also, because rather than typing gem install.... it would be easy to specify your gem requirements in Gemfile and running
bundle install

So, for that run the pre-requisite is
gem install bundler --pre

Furthermore, I am using Sqlite3 database server, you will have to install sqlite3 from http://www.sqlite.org/download.html.Choose sqlitedll-3_7_2.zip (265.70 KiB)and copy paste the exe file in your ruby/bin and do
gem install sqlite3
gem install sqlite3-ruby #(for connecting sqlite3 and ruby) 


If you just want to change the database server, you can simply change the adapter of your application_folder/config/database.yml.

Note: I am using "Ruby interpreter" for rails commands and cygwin for git commands.

Saturday, August 28, 2010

Brief Overview of Ruby on Rails

I still remember when we had to do our final year project, we had to write tons of code for building small application in programming languages other than on rails. However, Rails has saved the life of many programmers! In rails, we do not have to start from the scratch like making folders and files one by one. This is done by the rails itself. Write a simple rails command and all the required folders are generated. Isn't it awesome. Rails is the platform and Ruby is the programming language. The life of Ruby programmer is made easy through RubyGems, which contains files to install. They are like plugins, for example, if you want user authentication you can simply install gem called devise(I will come to this later on).

Moreover, Rails is based on MVC(Model, View and Controller) architecture. Models deals with data and database. View is what your user-interface will look like. Finally, controller connects the model and view. It's the job of the controller to control both the model and the view.

You will find many useful materials on internet but I could not stop myself from this brief introduction to "Ruby on the Rails". Finally, welcome to the "Rails World" (apart from "Hello World" ;) ).

Installing Cygwin in Windows

Installing rails directly on windows can be really troublesome(trust me on this). So, for windows lover (me included) I think installing cygwin (linux emulator) before installing ruby is a good idea. You can install cygwin from http://www.cygwin.com/. In the installation window, search for the following requirements: make,curl, ruby and git (for version control if you are using git) in your installation.  Also, select g++ and gcc if they are not already selected.