Ruby on Rails 3: The future of online web applications.

At the moment, PHP is undoubtedly the leading development language of online applications. It’s simplistic syntax and the prevalent amount of tutorials for it makes it a perfect starter language for online developers. The ability to include miniature chunks of code on any ordinary HTML web page makes getting started with PHP exceptionally easy.

However, there’s a new player on the block, Rails. With the recent release of Rails 3, building the next new killer application seems much easier and faster to accomplish. Rails 3 facilitates the development of online applications by providing developers with a powerful, scalable & expandable framework. Rails 3 has arguably introduced web developers with one of the finest object oriented programming languages.

There are a fair amount of powerful PHP frameworks that can be named. However, they all lack the powerful OOP features that Rails 3 provides. Models can be created as objects, then can be modified/saved into a database and destroyed at anytime. The powerful framework handles sessions, security, XSS, SQL injections and secures everything. However, the best part of this is the ActiveRecord ability to make optimized SQL queries without spending up all your time.

The workflow of creating a blog would be the following:

  1. Create a new Rails 3 application
  2. Create a post model (using a built-in simplistic scaffold application) with the following values
    • ID
    • Title
    • Content
  3. Create a comment model (same scaffold application) with the following values:
    • ID
    • Content ID
    • Related Post ID
  4. Use the automatically generated Post controller and write the following in it:
    has_many comments
  5. Use the automatically generated Comment controller and write the following:
    belongs_to post

There is much more to it, however, everything just makes sense. I strongly suggest taking a look at Rails for Zombies which is a simple introduction to Rails. Also, watching the Rails 3 screencasts won’t take more than a couple of minutes of your time but you will undoubtedly be interested.

Frankly, here’s a small comparison of a little query that gets the 5 latest comments for a blog, both in PHP and Rails. You be the judge.

PHP:
mysql_query(“SELECT * FROM comments WHERE id=1 LIMIT 5”);

Ruby:
comments = Comment.where(:id => 1).limit(5)

Also, if you have nested objects, you can obviously do the following with Ruby:

hard_drive = Client.where(:id => 50).computer.hard_drive

I don’t even want to start thinking of how complex and time consuming writing a query for the above code, where it’s all done and completed within minutes. I personally think that any advanced (or beginner) programmers should give it a shot. Nothing but advantages so far here, I’ve yet to run into a Rails issue. I’d love to hear others constructive output regarding this, I know I might sound a bit biased however I have been very impressed by Rails.

-DS

  • Jim

    That's comparing apples and oranges. Rails is a framework. PHP is a language. Your snippet about fetching Comments from the database is not accurate. You are showing RoR functionality, not Ruby functionality. If you want to compare RoR against anything in the PHP world, you have to compare it against something like Zend Framework, Symfony, Cake or Agavi. There is a host of PHP frameworks available. And frankly, while RoR3 might spark some more interest in Ruby in general, Ruby is currently not that popular. At least if you believe in the number published by Tiobe.

  • http://johnkary.net John Kary

    "I have reviewed numerous frameworks in PHP — Zend, Symfony, CakePHP, CodeIgniter, Kohana — None of them provide the capacity that Rails can provide."

    Not trying to troll, but, if you think Symfony or Zend Framework can't provide everything Rails can, you haven't read far enough yet.

    Start here: http://www.symfony-project.org/jobeet/1_4/Doctrin
    Look to the future here: http://symfony-reloaded.org/

  • liquidrums

    I'm with Jim. A closer macintosh-to-grannysmith comparison would be RoR3 to Symfony2(+Doctrine2), because of their tight integration.

    <code>
    comment = Comment.where(:id = 1);
    </code>
    would compare to:
    <code>
    $comment = Comments::find(1);
    </code>

    Doctrine2 also allows for:
    <code>
    $computer = $comment->getComputer()->getHardDrive();
    </code>

    RoR3 is HUGE on convention of configuration with sprinklings of magic, and PHP's popular frameworks decidedly require more bootstrapping & boiler-plate code. The real question comes down to, once you reach limitations in your tool, which will have more success extending?

  • http://ivanbernat.com Ivan

    I absolutely agree with Jim here. But even if you went on and compared Rails to any PHP framework, Rails would still be a clear winner due to the flexibility of Ruby and thousands of plugins available for Rails.

    I’ve just spent an hour doing something “trivial” in Cake that would take minutes with Rails (by installing a plugin).

  • http://fernandokosh.blogspot.com Fernando Kosh

    The problem with PHP is it online manual, because it has only strucured examples. Only after some years developing, the programmer see that they needs a framework, and they will build your own. Because that, we have more than 879523975937459 PHP frameworks, but no methods and conventions.
    This doc (http://www.dagbladet.no/development/phpcodingstandard/) from 2003 try to call developers to use standards.
    How manu PHP developers know that?
    With Ruby, the life another because hen you starts, you starts of the right way.
    Do right, and will be right.

  • Giuseppe

    I'm using Rails for several month, I can say that is fantastic, easy and snappy.
    But I'm asking myself: This framework came out several years ago, it's not a new technology, so why it is not so used as php or .NET ?
    Probably it's because it uses ruby as a language that has an "out of the standard" syntax that people don't want to learn because they are comfortable in php, java (servlet and jsp) .net that has a C syntax style ?

    I want to highlight that I was able to build a social network in 1 week and an half all alone using rails. Using other technology it would be impossible.

    I would like to know your thinks about it.

    • Jim

      Building a social network app in 1 week hardly conveys any details. The getting started video on rails site does it in 20 minutes…

      Dont get me wrong. I'm developing in RoR now and I've been doing PHP dev for 7 years. I simply love Ruby. As a language it's very modern and concise. The declarative nature makes it very nice to work with. It's lack of market share may be rooted from the lack of attention from academics? Students go to school, learn c, java, .net and scripting languages(i.e. php), but I don't think they offer Ruby as a curriculum. So it looses out from the start.

  • Dhawal

    WordPress, Joomla, Drupal plugins, Facebook Apps , wider hosting support and lot and lots of tutorials and forum to disscuss problem about PHP, so PHP is still #1, most coder don't give much for how cool they program, they want to get paid so they just want things to work. If tomorrow Ruby based CMS,API ect. get popular then Ruby might become #1, Python was trying to do that (from many years), but didn't make it, although its used by Google and NASA. Ruby and Python are same kind of languages but php is quiet different. PHP real competion is with .NET and JSP, while Ruby and Python can get popular but can't actually make it as common on web as php.

  • Farooq

    Jim.. Aggreed…School curriculum is an important point mentioned. MoreOver there are so many training institutes available for likes of PHP, JAVA, .NET etc.. But hardly any for ruby and rails…

  • http://twitter.com/zendkingrohit @zendkingrohit

    Learning a new Language simply depends on how strong your Object Oriented , SQL and Design Pattern Concepts are. Say for example you learn Java in your School along with Microsoft SQL Server and gaining complete Mastery over both. I would say learning or Ruby or any other Modern Language would be at most Matter of 1 Weekend.

    Rails is not a Magic Solution. Say for e.g. if you don't understand the SQL concept like using 2 or 3 JOINS for fetching Data from many-to-many related Tables then you wont be able to do it in Java/SQL and also you wont be able to do it in Rails either because of lack of understanding of concepts. If you dont know whats going on behind COOKIE and SESSIONS then you'll be scratching your Head in Rails too and so on…

    So , Understanding the Basic HTTP / Server / SQL / Headers etc etc. concepts is what matters the most and not the Language itself IMHO.