Ruby on Rails vs Yii2

Ruby on Rails or Yii2: for what each solution is suitable?
24 July 2017   1180
Ruby on Rails

Framework written in the Ruby programming language

When it comes to web development, usually PHP immediately comes to mind - a language designed specifically for Internet applications. It has existed for more than 20 years, so it is not surprising that for such a period, many frameworks have been released.

However, the web environment is not only the prerogative of PHP. A worthy competition to this language is Ruby. He comes to the rescue, if it is necessary to create not a blog or a corporate site, but an atypical solution. However, sometimes you can find standard Web resources developed in Ruby.

In this article we will compare the two most popular frameworks for Ruby and PHP - Rails and Yii2.

Accessibility for beginners

PHP has a low entry threshold - you can start writing code quickly enough without even having any basic programming knowledge. Many web developers start with this language. Because finding a web developer familiar with PHP is not a problem. On the other hand, Yii is not the simplest framework, because it Requires certain rules when writing code.

Yii2 interface
Yii2 interface

Ruby on Rails is more complicated at the beginning of the path, but then it can greatly facilitate the life of the developer due to the abundance of magic and gems. And the language itself has many built-in useful methods, for example, for working with dates or arrays.

Ruby on Rails syntax
Ruby on Rails syntax


Rails is inferior in speed to work, because Ruby is basically a slow language, and the framework inherits this problem. Yii is not just faster than RoR, it's the fastest PHP framework. Therefore, to create a project that is critical to high performance, Yii is the only alternative among all other solutions in PHP.

Libraries and extensions

The total number of plug-ins is about the same for both solutions. However, thanks to the fact that RoR has been actively developed and supplemented since 2003, most of its gems are reliable, time-tested solutions with a lot of background information, both from developers and the community.

Debugging tools

The most popular debugging tool for php is XDebug. This powerful solution was one of the first with the system of control points and offers developers on Yii a really great set of useful features:

  • Complete information about the current state of the program;
  • Changing the values ​​of variables during the execution of the script;
  • Remote start with two session modes;
  • Built-in support for xdebug-client in most popular IDE for PHP.

True, using this debugger may require additional settings for the environment where the application is deployed.

In Rails Debugger gem is used, which provides only the basic functionality, has not the most convenient mode of operation and the need to manually mark the place for control points with the word debugger.

CRUD-applications development

In Yii, there are excellent built-in tools for creating CRUD applications. GridView, ListView and DetailView are fully supported, there is a feature of checking and searching for jQuery. Additional comfort is provided by automatic generation of code using Gii, which creates a sufficiently high-quality script that requires minimal revisions.

Ruby on Rails also can offer support for tools for working with CRUD-applications, however for full use of all features you will need to use additional modules, for example, JS-library Ext and plugin Netzke.

Documentation and support

Both frameworks exist for a long time and therefore have detailed documentation that makes it much easier to find answers for any questions. PHP, as a more common language, has a large community that actively communicates with the forums and supports Yii. However, Ruby on Rails also has an abundance of supporting information, and in thematic communities one can always rely on help.

The situation with technology is different. PHP supports any inexpensive hosting, so you can use Yii capabilities almost everywhere, which makes the framework suitable even for small projects. Ruby is a more niche language designed for complex web applications and startups, and not all hostings support it, and where RoR is available there are sometimes limitations - for example, installing gems through a ticket for Techsupport.

Final comparison of Ruby on Rails and Yii2

Yii2 Ruby on Rails
A popular language and a framework with a low entry threshold. A niche language that requires time to learn from scratch.
High performance Lower performance
Not the most convenient syntax and readability of the code. Excellent code readability, many useful built-in methods
Powerful and convenient XDebugger Debugger gem is used for a debugging, Inferior to the capabilities of XDebugger
Built-in CRUD application suppport Additional gems and plugins are required for CRUD support
Detailed documentartion Less detailed documentation
Possibility to install framework on any hosting Not all hostings support Rails and some have limitations
Suitable for small projects Suitable for bigger projects


What technology do you choose, Rails or Yii2?

What technology do you prefer? Ruby on Rails or Yii2? Or maybe you are already using some of it? Please, share your thoughts with the community. Also, after the voting, you will be able to see what people like the most. Your opinion is very valuable for the Hype.Codes team.

DateTime, Timestamp, Time and Date in Rails

Learn about key differenece between DateTime, Timestamp, Time and Date in Rails
31 October 2017   617

The difference between different date/time formats in ActiveRecord have little to do with Rails and everything to do with whatever database you're using.

Using MySQL as an example (if for no other reason because it's most popular), you have DATEDATETIMETIME and TIMESTAMP column data types; just as you have CHARVARCHARFLOATand INTEGER.

So, main differences: DATE only stores a date, TIME only stores a time of day, while DATETIME stores both.

The difference between DATETIME and TIMESTAMP is a bit more subtle: DATETIME is formatted as YYYY-MM-DD HH:MM:SS. Valid ranges go from the year 1000 to the year 9999 and everything in between. While TIMESTAMP looks similar when you fetch it from the database, it's really a just a front for a unix timestamp. Its valid range goes from 1970 to 2038. The difference here, aside from the various built-in functions within the database engine, is storage space. Because DATETIMEstores every digit in the year, month day, hour, minute and second, it uses up a total of 8 bytes. As TIMESTAMP only stores the number of seconds since 1970-01-01, it uses 4 bytes.

You can read more about the differences between time formats in MySQL here.

In the end, it comes down to what you need your date/time column to do. Do you need to store dates and times before 1970 or after 2038? Use DATETIME. Do you need to worry about database size and you're within that timerange? Use TIMESTAMP. Do you only need to store a date? Use DATE. Do you only need to store a time? Use TIME.

Having said all of this, Rails actually makes some of these decisions for you. Both :timestamp and :datetime will default to DATETIME, while :date and :time corresponds to DATE and TIME, respectively.