HIT3304-2009HD ASSIGNMENT 6577377
RUBY ON RAILS
RUBY
Ruby is a high level programming language which is interpreted like Perl and Python. The main factors of ruby are, it is very easy to learn, it is open source, it has Rich libraries, Very easy to extend, truly object oriented and less coding with fewer bugs. Ruby is an interpreted language, like java script. That means there is no compilation necessary. You can just change you code and immediately run it.
RUBY ON RAILS
Ruby on Rails is a leading web application development framework, based on ruby programming language. It is extremely productive web application frame work. It provides a rich set of utility functions that make most common task simple. It uses model-view-controller design pattern.Flexibility of reusing this framework any number of times as we only need to install it once. Then we can implement it on any number of applications that we develop. One could develop a web application at least ten times faster with Rails than you could with a typical Java framework.An open source Ruby framework is used for developing database-backed web applications using the Model-View-Controller pattern, means entire application is segregated in three parts.
PATTERN
The Model Section helps us to analyze and design the data model for the application. It is also referred to as the domain model.
The View Section has everything to do with the look and feel of how the application presents the data model, or how application will be shown to user.
The Controller section of this model determines how the application will react to all the different events and instances which are associated with that application, ie how the model element will be controlled in response to application request.
CONVENTION OVER CONFIGURATION AND DRY
Ruby on Rails is intended to emphasize Convention over Configuration (COC), and the rapid development principle of Don’t Repeat Yourself (DRY).
Convention over Configuration means a developer only needs to specify unconventional aspects of the application, for e.g., if there is a class sale in the model, the corresponding table in the database is called sales by default. It is only if one deviates from this convention, such as calling the table products sold that the developer needs to write code regarding these names. Generally, this leads to less code and less repetition.
Don’t repeat yourself as suggested by the name of the principle, Ruby on Rails make repeating you unnecessary with the help of Active Record and the method of scaffolding.
Active Record is ROR specific implementation of the active record pattern which, according to me is a design pattern frequently found in enterprise applications.
With scaffolding, a compiler automatically generates basic pieces of code necessary for logistics of a website- for creating, reading, modifying or deleting data in the database. So one is left with a sort of template upon which one can build the rest of the website with more specific code.
Ruby is a programming language, Rails is a collection of ruby scripts. So the web server, the action pack application framework and the bundled tool scripts are all just ruby scripts and therefore part of rails.
APPLICATION EG:
I believe the best way to do that is to first give you a few examples of websites built on the RoR framework.
- Campfire
Created by the same 37Signal company.It’s a web-based group chat tool. You can set up in a matter of seconds a password-protected chat room and invite a client or co-worker to chat with you.
- 43Things
Make a list of your goals and share it for everyone to see.Meet people that want the same things as you do.Most popular on everyone’s to-do list currently seems to “be happy”
- Checkli.st
For shopping and travel checklist management.
- Coastr
A social guide to beer:) as they claim.Allows you to share with others your passion for beer.
- DiscoverMachine
Create and share your maps. You can even import your GPS data.
- 7bills
You can track an euro bill to see where it’s travelled in the world by entering the serial number.Very interesting!You can also see other recent searches conducted on the site.
- MyRecipe
A place to share your recipes.
HOW TO DEVELOP WEB APPLICATION
To develop a web application using Ruby on Rails Framework, install the following software:
- Ruby
- The Rails framework :We need a set of pre-written code to that will form the foundation of the web application
- A Web Server: We need somewhere to run the web application.
- A Database System : we need some sort of database where we can store the data
- An object relational mapping library: To simplify access to the database most web application now uses an O-R mapping library to convert the database records in to objects.
Regardless of what language you code in, you will probably still need these three things for your deployed application. One of the great things about rails is that it contains all of the software you will need –all bundled in for free.
There are many features available to you by rail you need to select which feature you need. You can uses each features only once in you application
1)Active record library
2) Budled emailer
3) Testing framework
4) SQLite3 RDBMS
5) Bundled HTTP server
6) REST based services
7) Action pack framework
8) server side graphics
Rails is for database-centric application like the ticked sales system
With the rail user can access and modify the contents of the database without using SQL direcly Rail includes an application framework called action pack that will help you generate data driven, interactive pages.
Secondly web application need to be run on a web server to display these pages, so rails comes with one built in.
Thirdly you need a database. Rails create applications that are configured to work with and integrated SQLITE3 database.
The fourth thing you need is an object relational mapping library and rails provides one called Active records. This make your database looks like a collection of simple ruby objects.
It also includes a pile of tool scripts to help you manage the application. So if you are creating a database-centric web application you will find rails gives you everything you need.
You create a new application with the rail command
1) Creating a new web application is actually really simple in rails. All you need to do is open up a command prompt or terminal window and type in rails tickets, where tickets is the name of the application you want to create.
Eg:>rail tickets
This will cleverly generates a web application in a new folder called tickets and also with in the ticket folder it generates a whole host of other folders and files that form the basic structure of a new application
Following folders are created
Ticket
- Readme
- Rakefile
- App
- Config
- Db
- Doc
- Lib
- Log
- Public
- Script
- Test
- Tmp
- Vendor
Application folder contains most of the code of you application
2) Because the application you have just created is a web application, you need to start the built in web server to see it running. At a command prompt or terminal, change into the tickets folder and type
>cd tickets
ruby script/server.
A few messages will appear on the screen that will confirm that web server is running. Now you can see that default home page by opening a browser at:
Rail starts its server on port 3000 by default. It you want to use another port, such as 8000, run
Ruby script/server –p 8000
3) Now you need to add you own code to the default app
Rails allow you to create your custom code related to you application easier. Rail created basic file structure for you as If it knows what you were going to need, because rail apps follow very strong naming conventions. This makes the application easier to understand, but it also means that the built-in rail tools will understand how your application works, and so you can use these tools to automate a lot of the coding task, that’s why rails can use conventions to generate code for you, without you having to configure you web application.
4) Rail can quickly generate all the code and pages you need by using scaffolding tool. There are simple command that you can issue from the console to generate the scaffolding codes. Scaffold is that command used to generate crud operation code
ruby script/generate scaffold ticketsname: string seatid : string address: text price paid: decimal email address: string
With this command we told the details of the data structure when we ran the scaffold command and there is a important principle in rails: Don’t Repeat Yourself. When rail generates the scaffolding it also generates a small ruby script called a migration to create the table. A migration is a script that alters the structure of the underlying database.
5) Migration is a small ruby script. To run the migration, type rake db: migrate at the command prompt. This runs the migration code and creates the table:
> rake db: migrate
6) Open the web browser and type localhost: 3000/tickets
Create few records by clicking on the new ticket.
7) scaffolding generated a whole set of pages that allow us to create, modify and delete ticket details.
In short the rail command is used to create a new application. Ruby command is used to run the tool scripts that are stored in the scripts folder. Rake is the command we used to run the database migration.
8) if you want to make some changes in the appearance of the generated pages you need to dig into the application architecture. As rail apps follow conventions over configuration this will make it easier for us to modify the application, because code separated according to its functions. That means ruby scripts that do similar things live in similar places.
9) if you want to add new caloum to your table you just type
> ruby script/generate migration addphonetotickets phone:string
> rake db:migrate
As whole the application is devided into three folder it is obvious that to change appearience we should go to view folder and you will find the file you want to update.
Workflow for creating Rails applications:
A recommended workflow for creating Rails Application is as follows:
- Use the rails command to create the basic skeleton of the application.
- Create a database on the MySQL server to hold your data.
- Configure the application to know where your database is located and the login credentials for it.
- Create Rails Active Records ( Models ) because they are the business objects you'll be working with in your controllers.
- Generate Migrations that makes creating and maintaining database tables and columns easy.
- Write Controller Code to put a life in your application.
- Create Views to present your data through User Interface.
Rail is the quickest and coolest development framework, allowing you to develop fully functional web application quicker than you ever thought possible. Getting started is simple all you need to do is install rails, and start turning the pages. Before you know it, you will be miles ahead of the competition.
1