Friday, 24 August 2012

The Smoothest Application Development Ride – with Ruby on Rails


Ruby on Rails has been the topic of discussion for years together, yet the capabilities of this cutting-edge technology are not known to many an application developer, in their entirety. What RoR application development provides is an enhanced and supremely productive path to the rapid development of web application. Here, we try to light the way to make this technology accessible and enjoyable to developer communities across the globe. So, the next time you hire RoR developers, you can be assured that your application will be up and running in no time at all.
Let’s start off with the basics! Ruby is an ideal example of a purist’s concept of a pure object-oriented language with an easy-to-write and maintain syntax that should be any programmer’s dream come-true. And Rails? A framework that is open source and is perfectly suited to the development of web-based, database-driven applications; that’s Rails for you. The advantage of this framework is its capability to develop applications up to 10x faster than technologies, such as Java! Ruby and Rails leverage each other and the two most important principles of lesser lines of code and convention over configuration are derived from this amalgamation. As you start developing RoR web applications, you’ll realize that the mount of code required is way lesser than other technologies. On the other hand, we have convention over configuration which cuts the umbilical cord for all XML files. You can literally do away with all XML configuration files, as simple programming conventions take their place.

Okay, now onto the main course! We will try and explain the process of developing a web-based, database-driven application using Ruby on Rails.

The Installation
Though Rails has always been a breeze when it came to installation and configuration, there are many tools available today that make this job even simpler. Based on your operating environment, you can choose any one of the following options: Instant Rails for Windows, Locomotive for Mac OS X, and Rails LiveCD for Linux.

The Purpose
The application we are aiming to design is supposed to show a list of all books, create and edit existing book titles, and categorize books to categories according to their genre, such as crime fiction or sci-fi. Designing the structure and defining the ground rules for standardizing such as app is important as the UI experience of a user should not differ from page to page.

The Process
Here we have our first brush with the iterative and incremental approach offered by Rails. Below are the steps required to develop any application in Rails:
Create a Rails Web Application shell (empty app)
Choose Rails’ default database name or specify one yourself
Create the database if it doesn’t exist
Pick and choose your application’s features
Create the tables that your app will use, if they don’t already exist
Create a code base for the tables
Optimize and modify the code as per your need
Repeat steps 4 -7 till your application development is complete

Step 1 - Create a Rails Web Application shell (empty app)
Rails provides an endearing feature where every Rails app has the same core structure. So, whenever you want to create a new app, Rails automatically generates a structure for this application. This is something that many Ruby on Rails consultants cherish as it affords them the extra bandwidth that they can invest in thinking of innovative features for the app. Your app will always reside under the Rails Root directory which may be termed differently based on the environment you use. Open a command prompt window and find your way to this directory. All you have to do now is christen your app. Type rails library (remember, our app is for a dynamic database of books?) and voila! Rails creates your app subdirectory and a tree of folders and files – your empty Rails app. Rails automatically writes code to most of these files in the various subdirectories. But there are a few that need a special mention:
app/controllers – contains all the controller classes. A controller is a component that handles incoming web requests from users.
app/views – contains display templates that are converted to HTML after filling in data and returned to the user’s browser.
app/models – contains classes that model and wrap the application database contents.
app/helpers – contains helper classes to do what their name suggests: help the model, view and controller classes in their function.

Step 2 - Choose Rails’ default database name or specify one yourself
The database we need to use for this application needs to be specified in a fixed format; its name concatenated with development, which in this instance means our database will be called library_development. We should also try and leave the development database password blank as it is a convention followed by Rails. If you ever need to modify the database name or password, all you have to do is access and edit \library\config\database.yml.

Step 3 - Create the database if it doesn’t exist
Now, we create our database. Ensure that the MySQL engine is running and log into the command prompt as a root user. Enter and execute the following commands:
mysql –u root –p
create database library_development
grant all on library_development.* to ‘ODBC’@’localhost’;
exit

Step 4 - Pick and choose your application’s features
Here’s what makes Rails different from other application development technologies. Any data we assign to rails, it assumes that we will need to create, read, update and delete it. In our case, we too need to create book titles, edit them, delete them, etc. Therefore after specifying the tables we want for the app, Rails will automatically generate all the basic code. Now, do you understand why Rails is up to 10x faster?

Step 5 - Create the tables that your app will use, if they don’t already exist
We are not going to dwell on creating on tables and defining foreign keys here. All we need to know is that 2 tables are required, one for the book titles and another for the categories with a one-to-many relationship.
After creating tables in MySQL, on the command prompt ensure that you are in the library_development directory and execute the following command:
mysql cookbook2_development <db\create.sql

If you return back to the command prompt, without any messages or error, everything went fine.

Step 6 - Create a code base for the tables

Here, we use scaffolding – a concept unique to Rails that allows us to generate a basic application structure without breaking a sweat. Execute the following command on in your app subdirectory:

ruby script\generate scaffold book book

This generates the model, view and controller files for the section of our app that will use the Titles tables. We do the same for the category part:

ruby script\generate scaffold category category

Step 7 - Optimize and modify the code as per your need

We will use Mongrel; a popular Rails-friendly web server for hosting our app locally. In the library subdirectory execute the following command to rev up Mongrel:

mongrel_rails start

And, we are done! A few more lines of code would be required to patch things up and display proper messages but mostly, our app is up and running in the blink of an eye!

We are a Ruby on Rails development company that has been leveraging its extraordinary advantages for quite some time, to design and develop cutting-edge application for our clients. We provide offshore software development services to companies and organization across the globe and have achieved a 100% development rate doing the same. If you wish to harness the tantalizing power of Ruby on Rails for the development of your application, do not hesitate to get in touch with us and hire RoR developers from our talent pool. You web application will be up and running in no time, and will function par excellence; that’s a promise!

0 comments:

Post a Comment