Rails 4 received new update

Ruby on Rails 4 received new 4.2.9 update that solves security issues.
27 June 2017   776


A dynamic, open source programming language, focused on simplicity and productivity

Ruby on Rails

Ruby on Rails (RoR) - a framework written in the Ruby programming language

New update for "old" RoR has been released recently. According to the developers' maintenance policy, since the release of Rails 5.1.0, the 4.2 series will only receive new releases in case of security issues. 


  • Action Pack:
    • Use more specific check for :format in route path
      The current check for whether to add an optional format to the path is very lax and will match things like :format_id where there are nested resources, e.g:

      resources :formats do
        resources :items

      Fix this by using a more restrictive regex pattern that looks for the patterns (.:format).:format or / at the end of the path. Note that we need to allow for multiple closing parenthesis since the route may be of this form:

      get "/books(/:action(.:format))", controller: "books"
  • Active Record:

    • Fixed regression caused by collection_singular_ids= ignoring different primary key on relationship.

    • Fix rake db:schema:load with subdirectories.

    • Fix rake db:migrate:status with subdirectories.

    • Fix regression of #1969 with SELECT aliases in HAVING clause.

    • Fix wait_timeout to configurable for mysql2 adapter.

    • Make table_name= reset current statement cache, so queries are not run against the previous table name.

  • Active Support:

    • Fixed bug in DateAndTime::Compatibility#to_time that caused it to raise RuntimeError: can't modify frozen Time when called on any frozen Time. Properly pass through the frozen Time or ActiveSupport::TimeWithZoneobject when calling #to_time.

    • Restore the return type of DateTime#utc
      In Rails 5.0 the return type of DateTime#utc was changed to Time to be consistent with the new DateTime#localtime method. When these changes were backported in #27553 this inadvertently changed the return type in a patcn release. Since DateTime#localtime was new in Rails 4.2.8 it's okay to restore the return type of DateTime#utc but keep DateTime#localtime as returning Time without breaking backwards compatibility.

    • In Core Extensions, make MarshalWithAutoloading#load pass through the second, optional argument for Marshal#load( source [, proc] ). This way we don't have to doMarshal.method(:load).super_method.call(sourse, proc) just to be able to pass a proc.

    • Cache ActiveSupport::TimeWithZone#to_datetime before freezing.

    • AS::Testing::TimeHelpers#travel_to now changes DateTime.now as well as Time.now and Date.today.

Check full list of changes. 


Feel free to use this checksum in order to verify your gem's version:

$ shasum -a 256 *-4.2.9.gem
bffbd5830a26af64d92548a831624a5422c77d97b2115c08b668fcbcc26f34ad  actionmailer-4.2.9.gem
8471fb1f9cc4962f3e000325821f1de0538a12cb580b0772ff9f89fbc8c1f9cd  actionpack-4.2.9.gem
d7fbbe069f74a6e7ce76cf91d0fede1593a0ed0db875f4630d8343551fb96f12  actionview-4.2.9.gem
a0086b19823d056efc1c8e7052d6684f54bebe7c9101ba69bd1a58c33d737451  activejob-4.2.9.gem
dbcd32a5e6294323b893565c0c334f6d89bb92d5085ce5e3d0454de0ed8eb5e3  activemodel-4.2.9.gem
0be77a1f77b2c8ae0e767c6fafb4c8fdda89c0be49ded0ae6f9644e81a4827a2  activerecord-4.2.9.gem
5717d2fe6409d4df72f0d20e46d7261503ccafc80ab228e91455d47185190ab4  activesupport-4.2.9.gem
eaaa4c1cafb3f9bd9f8dd58dd142522e398a5ad0d03abf2e3de364a63d4b7d1a  rails-4.2.9.gem
ad7b7765849a9aff0c42674f9512c39c098af63bb8476a4076a252fac3b4b2bc  railties-4.2.9.gem


DateTime, Timestamp, Time and Date in Rails

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

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.