2013年9月23日月曜日

Simple introduction about what is Ruby on Rails



I begin to learn ruby on rails since begin of this August. I found out that ruby on rails is awesome, it speed up all my works and make it simple to maintain. So, I wrote this article to introduce about how awesome rails is.
Back to our topic, what is ruby on rails? Web application development framework with ruby language. For more details, you can do some searching on what is ruby on rails, there are many sources you can found on internet.

Installation

It is always easier to be understood by running up the things.
To install rails on your windows or mac PC. There is a quick way to install it by download rails installer and install it.
To install rails on linux os such as ubuntu, debian might needs a little bit more works then windows and mac. There are sources on internet, check it out.

To begin a new project

Before getting start to develop a new web application. You need to setup database, directory of your new project, .htaccess to control the traffic. Maybe you will spent almost half an hours to one hours to setup all those things. But …
Rails, will do it automatically for you.
By typing a few commands for it, rails will do it for you. Here’s the commands.
rails new MyProject
cd MyProject
rails generate model Item name:string price:integer description:text
rails generate controller items index new create show edit update destroy
rake db:migrate
rails server

On first command, create new project and name it "NewProject". Second command create table name item and columns of name, price and description. Third command create directory for html file, ruby file and routes. Fourth command to startup database and last command to startup the server.

Everything will be setup within 1 minutes. It means, you can begin your programming after 1 minutes. Cool right!

Go to http://localhost:3000 and you will see the welcome message of rails.

 rails2

To check with the project generated, go to http://localhost:3000/items

The page is blank. This is because all you have generated is database, system and routes. There will nothing to show unless html code is written.

Scaffold

A powerful tool that prepared by rails called Scaffold. Scaffold will generate everything including database, simple system code, traffic, html layout code. It means, you can begin to coding from half way instead of blank file.

How to use it? By a few simple command

First create a new project. In this case, named NewProject
rails new NewProject

Then, generate scaffold with following command and startup server.
rails generate scaffold item name:string price:integer description:text
rake db:migrate
rails server

Here’s the result generated by scaffold. Check it out

 rails1

Instead of blank project, scaffold will generate a template for us to make a quick way to start.

End

It is the end of the article, do you think that ruby on rails is awesome?

0 件のコメント:

コメントを投稿