[headline h=”1″]This method is deprecated[/headline]
In the last two articles, I talked about what is Ruby and what is Ruby on Rails. and what is the meaning of MVC architecture. So we kinda have a general idea of what we will be talking about in the following articles. From this Article we will not only talk but we will start to create our first Ruby on Rails Application. and to do so we have to know what tools we will be using. and what is the best for us.
IN this whole Course I’ll assume that most of you are working on windows 7 machines. Ruby can be used in any operating systems and I’ll talk shortly on how to install the development environment on your system. So let’s get started. What we will do in this Tutorial is:
- Install Ruby: Ruby recommends to install Ruby 1.8.7 or Ruby 1.9.2.
- Install Rails: The current Rails version is 3.0.0 which were released August 29th, 2010.
- Install Database Server: For Database I’ll use MySQL Community Server 5.1.50.
- Testing your development environment by running your first application.
As we already know by now that Rails is an Open Source Web Application Framework written in Ruby. So to install Rails we first need to install the language and it’s package manager.
As a Windows user the easiest way to get Ruby running on your machine is by using Ruby Installer. This is a self-contained Windows-based installer that includes the Ruby language, an execution environment, important documentation, and more.
1. Simply go to Ruby Installer for Windows Download Page and select the MSI installer files. In this tutorials I assumed that you will select the latest version or Ruby which is Ruby 1.9.2. So you will need to download the Ruby 1.9.2-p0.
2. After downloading the installer file, run it and accept the terms then on the installation destination and optional tasks page, browse to the location you want your installed files to be located “I prefer to make a folder called Ruby on the same partition where Windows folder are”. and don’t forget to check the check boxes as in the figure below.
3. We have to make sure that our Ruby installation was successful. So we go to our Command Prompt “Start > All Programs > Accessories > Command Prompt” and type the following:
then hit enter. If no errors appears and the Ruby version displayed correctly as shown in the next image. Then you have successfully installed the Ruby Language on your Windows 7 System.
1. Now it’s time to install the Rails. Simply type in the following command in your command prompt to install Rails and all dependencies
gem install rails --include-dependencies
This will take a while depending on your internet connection. So you can set back and grab yourself a cup of coffee.
2. If everything went okay you should be able to see something link the previous image. at that point you have done so good. next step is to install our Database server.
3. now we need to install the required gems for rails and that can be made by running the following command in your command prompt:
and now you are ready for the next step.
Installing Database Server:
I’d prefer to use MySQL as a database engine for my Rails applications. However you can feel free to use SqlLite3 which is by default the database engine associated with Rails.
1. Download the MySQL Community Server 5.1.50 select the recommended MSI Installer Essentials.
2. After downloading and running the installer make sure to choose complete on the first screen.
be sure to check on all windows warning before proceed.
3. After completing the installation wizard you will find a check box to start configuring your server
click on finish and let’s start customizing your MySQL server.
4. Follow the following screen:
a. Detailed Configurations
b. Developer Machine
c. Multifunctional Database
d. MySQL Datafiles
e. Decision Support (DSS)/OLAP
f. TCP/IP Networking Port Settings & Firewall Exception
g. UTF-8 Language Support “because we might write down stuff in arabic or in any other language than english and western languages”
h. Service Name
j. Security Settings
Hit next then execute and wait till all check points are green and voila, your MySQL server is ready… Next step is to test your installation and check if your computer is ready for the rails or not.
Testing your development environment:
1. Open a new Command Prompt window and navigate to the folder you want your projects to be created. I’ve created a new folder named it “Ruby Apps” and placed it in the root of my D: partition.
c: Users Hashem>D:
D:>md "Ruby Apps"
D:>cd "Ruby Apps"
2. Now we will create a test application with the name of “my_app” and to do so we type the following command in the command prompt window
rails new my_app
Now a folder will be created including the complete folder and file structure for your new application.
3. Now it’s time to run the server and test the application we just created. Ruby installation comes with a build in web server called WEBrick. To run the server navigate to the newly created application and run the following command:
D:Ruby Apps>cd my_app
D:Ruby Appsmy_app>rails server
The WEBrick will communicate to your localhost via port 3000. so now head up to your browser and open
If everything went ok you should be now looking at the Ruby on Rails: Welcome aboard default page.
- The server will be closed if you terminate the command prompt window at any time. so be sure to leave that window open during the whole process when developing an application.
- To terminate the server manually press “Ctrl + C” or just hit the close button.
You are done
Congratulations, Now you have created and tested your development environment. If you faced any problems please do not hesitate and post them in the comments and I’ll get back to you with the answer at once.
Next time we will get more into creating our first simple Rails application. so stay tuned and you might wanna subscribe to our weekly Rails newsletter. Till we meet again, Have fun & Happy riding…