Pubudu Kodikara
Leafy Code Blog
Published in
4 min readDec 6, 2015

--

Why I ditched PHP for Ruby on Rails

Currently my language of choice is Ruby on Rails. But before going for Rails I did my stuff in PHP. Even worked with it for some time. Later, when I did some research I found out that there are newer and better options for Web Developers. So I wanted to try Rails and never thought of going back to PHP again! Here’s why…

First of all, PHP is a language and Rails is a Framework

Many people misunderstand Rails as a programming language. The language we are using is Ruby. It was developed in the mid-1990s by Yukihiro Matsumoto (We call him `Matz`) in Japan. Ruby on Rails is a framework built using Ruby which adds more functions and improve the existing ones. So technically comparing Rails to PHP is a bit unfair. But still, even Ruby alone can be better than PHP because it’s so easy to use. The main goal of Ruby is to make things more simple and productive!

You can easily add missing functions through plugins (gems)

In PHP if you need a special function you can write it on your own or get the code snippet from a third party source and add it manually. Sometimes you would have to edit several files to get the work done. But for Ruby we have something called gems. This is a plug in system. Let’s say you need to add a complex user sign up and sign in system to your app… For Rails, there’s a very powerful plugin named Devise. This plugin can add a fully featured user management system to your app (It even have OmniAuth support). If you need its features, simply add the name of the gem to the `Gemfile` of your app and run `bundle install`. Now you can use all the functions it offer on your code. Like this there are thousands of gems available for you to use.

You don’t have to write a single SQL query! Rails does the heavy lifting.

Sometimes dealing with databases can become a lot messy. You might have to write lengthy and complex SQL queries to get your work done. Trust me I have tried them! Onn Rails, you don’t have to write SQL on your own. Rails’s own Active Record will handle the SQL queries. You have to deal with the database just like you deal with an object. For example, in a client database, if you need to find a client with the ID 10, you have to write this SQL code : `SELECT * FROM clients WHERE (clients.id = 10) LIMIT 1`. In a Rails app, you can do this using this code `Client.find(10)`. Simple and easy.

Some stuff can be easily generated

Now lets say you need a database called Clients and a way to add, edit and delete the records. You can use Rails to generate a scaffold for this. With one command you’ll get all the functions you need. But personally I do not recommend this. The more you write your own code, the better.

Great testing tools

Rails have some cool testing tools built right into it. You can use that or a more advanced system like rspec. Rspec is built for Test-Driven Development. First, you write the tests (even before you write a single line of code). In the tests you’ll tell the systems what you need it to do. Initially, all the tests will fail. Then you have to write the code to make the tests pass. Yeah, I felt awkward about this approach at first, but now im more than happy to use it! You can even use a system like Guard for real time testing.

Easy to run a development environment and deploy

If you need a temporary server set up on your local machine to test your PHP code, first you need to install Apache, then install MySQL, then configure them. Quite a lot of steps… If you need to run a server in Rails, simply type `rails s` inside your app. To create the databases `rake db:create` and to set the database structure `rake db:migrate`. Deploying it to a web server is also very easy. You can even use a system like Capistrano to make things even easier. With Capistrano, after making the changes to your website, simply run `cap production deploy` in your local machine and it will automatically connect to the remote server, upload the updated files and restart the server!

There are also some bad stuff…

Some people say there are some performance issues with Rails. Like inability to handle large traffic. That’s the same thing they said about PHP until Facebook proved it wrong. I think if you know how to use Rails well, this won’t be a problem for you. With the right tools, you can do anything!

Finally…

At the end of the day, Ruby on Rails wins my heart. But there are stuff that Rails can’t do. I have heard nice things about Nodejs. A new javascript based platform for developers. You don’t have to learn web development separately if you already know javascript! It can handle a lot of traffic without any issues. That’s something I need to try next. What I think is, these new technologies are already taking over the market. What do you know… in several years they will become the main language used by all the developers! So why wait? Try it now!

--

--

Pubudu Kodikara
Leafy Code Blog

Im a Blogger, Web Developer, Designer, and an inventor :)