Four Ways Ruby on Rails Can Help You

May 3 2009 by Phil McClure | 42 Comments

Ruby on Rails, an open source web development framework, has revolutionized the way we create web applications. By giving developers the necessarily tools and components needed to build powerful apps in an intuitive development environment, RoR makes development more efficient and less troublesome.

Four Ways Ruby on Rails Can Help You.

In this article, we discuss some of the ways Ruby on Rails can help you in rapidly building fully-featured web-based applications.

1. Rapid Development and Prototypes

Rapid Development and Prototypes

Issues caused by old techniques

When developing a website for a client, I want to concentrate on the clients needs i.e. the domain problem at hand. I don’t want to start thinking about setting up mountains of configuration files. Having to deal with such annoyances just delays what you are actually trying to achieve i.e. create a website which is specific to your clients domain. With conventional web development techniques, this issue can slow down the development process.

How Rails can help

Ruby on Rails uses a concept called Convention over Configuration which makes you follow conventions while you’re coding, leaving you with little configuration to do. For instance, if you created a model class called “Post” the corresponding database table will be called “posts” and the controller class will be called “PostsController”.
Further to this, Rails has a nice feature called scaffolding. Scaffolding allows you to create useful prototypes for clients in super fast times. However, a word of warning, it is deemed bad practice to use scaffolding code for actually building the final draft of a web application.

2. Structured Code and Neat Markup

MVC

Issues caused by old techniques

The main problem here, is separating the view markup from the business logic. A lot of old ASP and PHP web application have the business logic code scattered throughout the HTML. This makes life very difficult for, not only the programmer maintaining the code but the designer who is trying to find the markup. Needless to say, things were very unstructured in the web development days of yore.

How Rails can Help

As with many web frameworks, Rails uses the MVC compound design pattern to solve this problem. MVC (model-view-controller) splits the business logic into a “Model” layer and the view logic into a “View” layer. The “Controller” interacts with the Model and passes the required data onto the View. A full HTTP request cycle can be simplified into the following steps:

  1. The user sends a HTTP request by typing the required URL into the browser. This request is routed to a specific method in the controller.
  2. The method, being executed on the controller, interacts with the required model, which will usually retrieve some data from the database.
  3. The controller then passes control to the view, which specifies which HTML elements should be rendered and makes use of any data passed from the controller.
  4. The prepared HTML response is then passed back to the users browser.

So, what does MVC do for you? You will have clean, structured code, which is easily maintainable and very flexible. Enough said.

3. Interchangeable Databases

Databases

Issues caused by old techniques

I’m sure plenty of you have been there; Just created a lovely new, fully working, website using MySQL as the DBMS then, out of the blue, the client says "Oh Yeah, we don’t use MySQL, we use…". What do you do? Panic about all those embedded SQL query strings scattered throughout your code?

How Rails can Help

With Ruby on Rails this is not a problem, why? Well, Rails is database independent, meaning you can simply make a few configuration changes and hey presto, you’re now using Microsoft SQL or Oracle or SQLite (I could go on).

Further to this, Rails implements a design pattern called ActiveRecord to achieve Object Relational mapping (ORM). What the hell does that mean!?, I hear you say. This basically means that classes in your code can map directly to tables in your database. You can even define relationships between those objects in your classes.

ORM makes it simple to query the database without using database dependent SQL query strings, contributing to database agnosticism.

4. Database Schema Control

Sign

Issues caused by old Techniques

When working in a team of more than five, it can become hard to keep track of what changes are being made to the database. For example, someone could make a change to the database, removing a field from a table. Meanwhile, you could be writing code which expects that field to exist, simply because you are using an old revision of the database schema.

How Rails can Help

Rails solves this problem with Migrations. Migrations are called "Migrations" because they migrate the database from one state to another as a new modification is made. When changes are made, your fellow developers can run a simple command and they will be on the latest version of the database. Migrations are basically version control for your database schema.

Summary

To summarize, Rails does have a lot of new concepts to learn. However, this upfront learning curve will start to pay off when you see how much the framework gives you back in return.

About the Author

Phil McClure is a Software Developer from Belfast, Northern Ireland. His main interests are software architecture, design patterns and how these can be applied to web development. Phil blogs at theRailWorld.com. Follow him on Twitter.

42 Comments

Derek Neighbors

May 3rd, 2009

This is a good overview of many of Ruby on Rails benefits. I think MVC + Ruby + Convention over Configuration goes a long way. :)

Jeff Gran

May 3rd, 2009

Thanks for the great introduction to what makes Ruby on Rails different and better than other solutions. It seems like if I decide to learn a back end technology, this would be the way to go.

karthikkumar

May 3rd, 2009

I have been thinking about giving ROR a try. Nice post BTW.

HollsK

May 3rd, 2009

What would be really useful is some reviews of hosts that offer decent Rails support. Those guys are rarer than hen’s teeth. Unless you want to run the server yourself, you’re going to have issues finding a host to support it at business capacity at the moment. Hopefully that’ll change in the next few years, but in the meantime, it can be prohibitively expensive for small-scale projects.

Jacob Gube

May 3rd, 2009

Thanks everyone for leaving your opinions. I’m trying to convince Phil to keep writing about Rails, so hopefully you guys can help me! :D

@HollsK: “Those guys are rarer than hen’s teeth.” I feel you. I vouch for Slicehost if you’re looking for an affordable host that rocks in RoR support. Go in the chat room, you’ll get all your questions answered by the owners. Not affiliated with them nor do I get commissions on referrals, I’m just a really proud Slicehost’er.

Tixz

May 3rd, 2009

There’s nothing in rails that can’t be done with any mainstream PHP framework like Zend Framework, cakePHP etc.

But it is indeed nice to work with!

designcode

May 3rd, 2009

I’ve installed the RoR a few days ago, and tried a few things, I must say its rocking. But as far as we’re concerned about MVC or object-table mapping, these things can be achieved easily in PHP, I’ve written a small framework myself to make the application work this way.

halfright

May 3rd, 2009

1. because of scaffolding, I can agree this is true.
2. Same mistakes can be made of putting business logic anywhere, this is more based on skill level of programmer, this is not a benefit of just ROR. Any solid mvc architecture in any language, the same can be applied. With experience comes understanding.
3. This is also not a benefit of ROR. Come on you honestly are telling me that you can’t use different databases with different language stack. This is a joke.
4. Migrations are powerful, and very useful. This point I will agree with you.

Jacob Gube

May 3rd, 2009

@Tixz: Oh definitely, those are great PHP frameworks.

@designcode: Yep. MVC is a software design pattern so it’s not unique to RoR. Zend uses the MVC pattern as well. Though this post is specific to Rails a lot of the things discussed here applies to a web application framework.

Phil

May 3rd, 2009

Thanks for the comment everyone.

@designcode: MVC is achievable in many languages, however, I wouldn’t say it can be “achieved easily”. There’s a reasonable amount of work and thought that needs to go into it, IMO anyway. This is where frameworks like RoR and CakePHP come in. They save you reinventing the wheel each time you start a new project.

Phil

May 3rd, 2009

@designcode: Same goes for object relational mapping. It’s a pretty big task (in my book) to achieve this. Rails uses the ActiveRecord pattern (Martin Fowler) – Have a look at how this is implemented in the Rails code, it’s not something I would want to tackle too often.

paul

May 3rd, 2009

I have tried ROR development, but I always seemed to hit a wall when trying more advanced things, like many to many relationships, forms, multicriteria search,…
and the good books on advanced topcis are outdated, or by the time you get through the book, it is outdated.
You need to be permanently on the cutting edge.

Jonathan Nelson

May 3rd, 2009

Great article.

@paul (the guy right above this comment) you should check out Ryan Bates plethora of Ruby on Rails screencasts at http://railscasts.com. You’ll find awesome videos to some of those advanced techniques you just mentioned.

Eric J. Gruber

May 3rd, 2009

Slicehost is a great host, and I hear Dreamhost has decent Rails support as well. Check out the Hosting section at http://rubyonrails.org/ecosystem to get started learning about webhosts.

Paul, check out Pragmatic Press. They have beta books, which stay in development until the final release of the book. I find Pragmatic Press to be invaluable. (No affiliation as well).

As for “You need to be permanently on the cutting edge,” welcome to Web 2.0 (and beyond).

been around the block

May 3rd, 2009

ROR’s cool, but I much prefer the PHP MVC frameworks that are out there. For those of you looking for a easy yet powerful framework look at codeigniter.com. If you know PHP you should be able to pick that thing up in a night and have have it working for you by morning. Having used quite a few frameworks, codeigniter is fast, powerful and sweet to use.

My 2 cents,

jack

May 4th, 2009

ROR is good language for quick and fast workings, however it is strict.

but im afraid the general overview is that RoR is NEW, thus people don’t know a lot about it.

All the languages i worked with were MVC based frameworks just most of them were not as technical as RoR.

All languages support DB interactions that is a major requirement for them, changing from one DB to another with php is not necessarily hard, php can be used to develop scripts for another database for which it doesnt directly have access to.

Web server supporing RoR are very few and far apart, and i believe most concepts that ROR supports are already in use.

I also agree with designcode, a lot of programming is not up to the MVC language its up to the coder and as for RAD, its a methodology, come on i used RAD in my project to lead its progress.

Gary Barber

May 4th, 2009

You know what I would really love to see. Someone talk about RoR from a non developer view, from a designer with some dev experience. Such that a designer can see the benefits of using RoR.

Not seen this anywhere to date.. Is RoR really just a trendy dev Platform and that is it? ;)

Jack

May 4th, 2009

I dont like Full stack frameworks.. and I dont like Ruby (or Rails). But that’s just me. Go ahead if it suits your needs.

Charlie

May 4th, 2009

Good instructions for new users of the database schema, and structure of Ruby on Rails. Helped me to understand the use of Rails, and how it could be of an advantage to me.

Will

May 4th, 2009

Interesting. I’ve only just dipped my feet into PHP but I’d like to see some more about RoR, especially for us newbies.

Jacob Gube

May 4th, 2009

@paul: That’s the biggest problem of any new(er) technology. There are a lot of changes at the start. I agree that you need to stay up with the “cutting edge” to be effective with Rails.

@Jonathan Nelson: Thanks for sharing that resource in the comments – it’s a great site to check out.

@jack: Great counter-arguments – the main thing with RoR is that it is considered as the “new guy”. You have solid, stable, high-performance languages like PHP that’s been tested in a lot of large scale web apps like Digg that receive huge traffic that PHP is known to handle. Then you look at Rails’ flagship application, Twitter which has a very simple web interface; it’s always overcapacity, then you begin to think…

What I like most about RoR, from a PHP developer’s perspective, is its syntax. Ruby, to me, is very intuitive and clean.

@Will: When I considered a switch (PHP->RoR), this is a site I found very useful: http://railsforphp.com/

Phil

May 4th, 2009

@paul Yeah, RoR has many cutting edge features and yes there is a learning curve associated with it. Make no mistakes, you will have to put in some effort to learn ruby on rails, but it’s worth it. However, even if you decide to go with another language like PHP, you will have learnt stuff like MVC which is increasingly becoming a requirement on your CV/resume. It takes time for these things to sink in, but everytime you come back to it, you will get a bit further – so keep trying!

Max

May 4th, 2009

As a former PHP developer that made the switch, I also prefer RoR.

I prefer Ruby to PHP. I find the syntax to be much cleaner, more intuitive, and I can do more with less code. Not having to type ({}, $, ->, and ;) is also great.

CakePHP is still my favorite PHP framework, however, to me Rails is much better. I find it to be more stable and just easier when it comes to sending emails, associations (belongs_to, has_many, has_many :through), and forms.

I still use CakePHP but usually only for projects where the client refuses to change their hosting.

As far has hosts, I love http://railsplayground.com. They are by far the best RoR host I’ve used. You get support in minutes not hours and you can also login to their chatroom and get answers to your questions immediately.

I agree with jacob. RoR is still considered the “New Kid” that’s why it’s still probably not a good choice for “high performance” or very large apps. PHP has been tried and proven. But as RoR becomes more popular, we will see more solutions addressing these issues (performance and efficiency). Remember back in the 90s when Java came out? Some of the arguments made against servlets and JSPs?

jack

May 4th, 2009

@ Jacob

I agree, rails is definitely cleaner coding in my opinion as a Software Engineer it has many similar features but it is more strict and thus means cleaner coding and better code,

but RAD doesnt really suit clean coding as such its more designed for quick and dirty code that does the job, however, ruby cuts down the time programming which when coupled with RAD it does produce clean code.

As far as designing is concerned, rails has the ability to be modular and is more designed this way with the MVC concept which means more time can be spent developing all sorts of code and reuse is a definite good thing, many web applications during my research of how projects come together talk a lot about using similar libraries all the time etc so with a good model in RoR this can be used to link snippets in libraries together etc.

Michael Savage

May 4th, 2009

I just saw this on twitter as I was looking at my Simply Rails 2 book sitting beside me well done sir!

Phil

May 5th, 2009

@Gary Barber – The main benefit of Rails, to a designer, is that they will (should) be working with very clean HTML, making CSS work a lot easier.

slabounty

May 5th, 2009

If you’re new to ruby and frameworks in general, you might want to check out Ramaze (http://ramaze.net/) as a framework with Sequel (http://sequel.rubyforge.org/) as an ORM. I’ve done a series of posts on my blog (http://steamcode.blogspot.com/) about them that may (or may not) help you get started.

Karlon

May 7th, 2009

I think rails is losing more and more popularity. See also this chart.

http://www.google.de/trends?q=%22ruby+on+rails%22&ctab=0&geo=all&date=all&sort=0

Any comments?

Michael

May 11th, 2009

@Karlon

I tried a few other languages/programming paradigms (.net/dotnet/c#/java/php) and the only one I found that has been gaining any steam recently is objective-c. I presume obj-c is hot because of the iPhone.

IT in general is going through a down period and that reflects on the searches for all languages.

Umur

May 12th, 2009

Yet to try Ruby? Experience how you can create an online db with Rails now: http://conceptspace.wikidot.com/blog:19

employee clockin clockout

May 13th, 2009

can anyone shed some light on how this performs compared to visual studio?

Michael Riley

May 20th, 2009

I used railspace to get accustomed to the entire ruby fad, but i still am really preferential to PHP frameworks still, from a consulting perspective, i feel better knowing i’m creating code that i can easily hire other people to work on.

Joe

May 23rd, 2009

Php on Trax rocks the house for a php alt to Rails. It has many advanced features of rails built into it. Check it out. http://www.phpontrax.com

DemoGeek

May 29th, 2009

I’ve tried twice to dwell into RoR with determination but ended up backing out given the deployment overheads. Are there any easy deployment solutions to a RoR app other than Capistrano?

Phil

June 3rd, 2009

@DemoGeek – Yeah, Phusion Passenger (www.modrails.com) check it out!

Jeff

August 26th, 2009

ROR would be close to perfect if it provided an alternative to erb files which mix markup and code and allowed for a separation of concerns – markup only html files.

Jeff

August 26th, 2009

Phil,

ERBs do no promote clean code. Take a look at Apache Wicket for an example of a Java based MVC framework that does not allow the mixing of markup and code. In Wicket you have clean html files and you have java code in java classes manipulating elements in the htlm.

There are many things I like about ror. I only wish it would provide for the separation of markup and code as does Wicket.

Many one day it will and then I will give it another look-over.

Brandon

November 18th, 2009

I work in RoR as a designer and prefer it over many other options. I’ve worked in PHP but mostly with systems like WordPress, Drupal, Joomla, etc. I love the views convention and find any erb snippets of code really easy to work with and to understand. I think the separation of code is totally fine.

Do the people barking at RoR and trying to bury it know it as well as they know their PHP or other languages? How can you make a fair assessment without comparing equal knowledge?

As far as the comment on keeping on the cutting edge, I agree with Eric J. Gruber, welcome to web 2.0. The next generation of the web and the current economy requires more intelligent developers and designers. You need multiple weapons in your arsenal.

Karen

January 2nd, 2010

There’s no doubt that RoR is a great way to go, but depending on your needs PHP still might be a good solution. We’ve done a few awesome projects with RoR and prefer the view convention over anything else. Nice post BTW!

Ashok

January 19th, 2010

Hi,

You have written a good article and have done some good research.

Thanks,

Aarthi Raj

February 28th, 2011

Wow… this simply,clearly explains y one should use ruby on rails….

Miraç

March 7th, 2011

Hi;
Thanks for the post.
I don’t use Ruby as the primary language.
Because few job opportunities in Turkey.
Do you have job opportunities for the United States and Japan?

Leave a Comment

Subscribe to the comments on this article.