Ruby on Rails 5.1.4 RC1 and 5.0.6.RC1 released

Updates for two version of Ruby on Rails framework available now 
28 August 2017   689

Good news for Ruby on Rails coders. New 5.1.4 release candidate 1st version and 5.0.6 release candidate 1st version has been released. Final release is p


Let's check what's new for every version.

Rails 5.0.6.rc1

  • Active Record
    • Ensure sum honors distinct on has_many :through associations


Feel free to use this checksum in order to check version of your gem.

$ shasum -a 256 *-5.0.6.rc1.gem
0490ac6c4621756871839ad584f0a0349a72a9ccdeac0f72dafd3539638ba5ef  actioncable-5.0.6.rc1.gem
fc7697724d884307bf2ea307c028902f71f96304b9a882418e6ec94d10202cd9  actionmailer-5.0.6.rc1.gem
b0f1f4479f61ada80b3dbe3e9ccaa0db390119918e5da632dda3c8398e6e4f5f  actionpack-5.0.6.rc1.gem
673d06523edf733163ad668fe3cd64bd1c7fb97244c952241d1e00ee6835101b  actionview-5.0.6.rc1.gem
ac6521d4df459db19fc0f2740d0e0c0a6f3102252c8124ecb25e8d33335d6cf4  activejob-5.0.6.rc1.gem
0824cd58f175a3c825dce9d42d73254d25af25d824ae1c5c3465f12bb0812f72  activemodel-5.0.6.rc1.gem
7972a8a76c711b8fc01ab52d95c4f16a73e9683e4d745a17d61ab91051df856c  activerecord-5.0.6.rc1.gem
40f0c77de7e54b6a3581272ce5b6409ae0c61b5bfad3239db46807d8342ce8a3  activesupport-5.0.6.rc1.gem
7873311d5340bffbabeb33cb9d3ce2c97056bc2bebad3abfcba6f5b38b209075  rails-5.0.6.rc1.gem
3fd4b347f19fb4ff2ec7cee4c9a45aba31d1e287583943269bc9d09bef61ca93  railties-5.0.6.rc1.gem

See GitHub for additional information.  

Rails 5.1.4.rc1 

  • Active Record

    • Ensure sum honors distinct on has_many :through associations

    • Fix COUNT(DISTINCT ...) with ORDER BY and LIMIT to keep the existing select list.

    • Fix unscoped(where: [columns]) removing the wrong bind values

      When the where is called on a relation after a or, unscoping the column of that later where, it removed bind values used by the or instead.

      Post.where(id: 1).or(Post.where(id: 2)).where(foo: 3).unscope(where: :foo).to_sql
      # Currently:
      #     SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 2 OR "posts"."id" = 3)
      # With fix:
      #     SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 1 OR "posts"."id" = 2)
    • When a has_one association is destroyed by dependent: destroydestroyed_by_association will now be set to the reflection, matching the behaviour of has_many associations.

  • Railities

    • Allow irb options to be passed from rails console command.


You can use this checksum to check version of your gem.

$ shasum -a 256 *-5.1.4.rc1.gem
6ebb05e31a5d46379f638092742aa1543ab3522302a62351de9e5dc746fc7c77  actioncable-5.1.4.rc1.gem
fb3e3743a29a70524c64caa656056f7cf0085998a1438b28325c6e10a6330efd  actionmailer-5.1.4.rc1.gem
c4b39e9b721a4b2eb37be9f18bfbc0a479b61ae4d6b536b1b9f2fc06f83f6ad8  actionpack-5.1.4.rc1.gem
9930cccacbe71085b894ca0410da07625b801c4db1775b655357bd2bf5824ae9  actionview-5.1.4.rc1.gem
e0c7610f4fe20c778e5f9739f80ae4d5d3450bbacff49d24064b0b3b048f9dd6  activejob-5.1.4.rc1.gem
11dae082bd1dfea9541a60501135bef6c32d792407dea57250dc95ba5e415a77  activemodel-5.1.4.rc1.gem
3b058a80c8f14c324dad4c185825a4ce4c4f853af37002bec92e179bef583fcb  activerecord-5.1.4.rc1.gem
c9984249c0200e9c1f462779294e0cec6bb6c8b95421dc01b579a0efa2db6561  activesupport-5.1.4.rc1.gem
c8134e1efcc5f17ac28927a76423146f3a7baf618d97a5d752d09edf4c5eeb7c  rails-5.1.4.rc1.gem
7589a79f6b4a4de73d2d427193eb9beacd1628530958dd4d8f9404531748a973  railties-5.1.4.rc1.gem

Learn more at GitHub.

If you will face any issue, developers ask you to create an issue and mention @eileencodes.

DateTime, Timestamp, Time and Date in Rails

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

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.