This Week in Rails: Freeze strings related to caching, query optimization for Postgres and more!

Hey everyone 👋

Prathamesh here with the latest from the world of Rails.

⚡️This week’s Rails contributors ⚡️

This week was full of improvements and bug fixes. We have 24 awesome people contributing to Rails with 3 first-timers!

Improved

This change freezes the common strings used for fragment caching reducing the string allocations every time a read/write operation is performed on the fragment cache. The patch showed proper object allocation benchmarks showing a noticeable improvement, so it was accepted.

Optimize query for finding primary keys of a Postgres table

This change simplifies and optimizes the query used to determine the primary keys of a PostgreSQL table improving the overall setup time.

Fixes

Fix generator command for namespaced Rails engines

This change fixes the default generators to create proper namespaced resources for a namespaced Rails engine. For e.g. if we have a namespaced engine bukkits-admin , then

bin/rails g scaffold User name:string age:integer

will now correctly create

admin/app/controllers/bukkits/admin/users_controller.rb.

remove_index method can remove expression indexes now

Now, remove_index method can also be used to remove expression indexes apart from simple column indexes.

That’s it from This Week in Rails. There were many other great contributions, too numerous to list here, but feel free to check them out

See ya next week 👣

This Week in Rails: Ruby 2.4 on Rails 4.2

Hello! This is Tim , bringing you another edition of This Week in Rails.

This week’s Rails contributors

This week saw contributions from 26 contributors, including 4 for the first time! What a fantastic bunch!

Rails 4.2.8.rc1 has been released!

If you’re using Rails 4.2, you may want to get a head start by trying out the release candidate for the latest patch release. It’s the first Rails 4 release to support Ruby 2.4, so see if you can give it a try to help us iron out any kinks!

Improved

Deprecate locking of dirty records

ActiveRecord::Base#lock! and #with_lock reload the record before doing the actual locking. If there were any unsaved changes, they will be discarded without any warning. When this work is completed in Rails 5.2, an exception will be raised when trying to lock a dirty object. Until then, support for this has been deprecated, so keep an eye out for warnings like these!

Remove support for strings in callback conditions

If you’ve seen deprecation notices concerning strings used in if and unless conditions in callbacks, listen up! Support for these have now been officially removed. Time to update, if you haven’t already!

Fixes

Allow ActiveRecord::Base.as_json to accept a frozen Hash

As you may know, ActiveRecord::Base.as_json takes an (optional) options hash. That hash is modified internally, but Rails is nice enough to clone it first so that it doesn’t change the thing you passed to it. If your thing was frozen however, it would cause it to blow up! How can this be so, I hear you ask. Well, when you clone an object, you also clone its frozen-ness. dup , on the other hand, does not do this, which turned out to be the solution. Case closed!

That’s it from This Week in Rails. There were many other great contributions, too numerous to list here, but feel free to check them out!

See you next week!

[ANN] Rails 4.2.8.rc1 has been released!

Hi everyone,

I am happy to announce that Rails 4.2.8.rc1 has been released.

If no regressions are found, expect the final release on Wednesday, February 15, 2017. If you find one, please open an issue on GitHub and mention me (@rafaelfranca) on it, so that we can fix it before the final release.

CHANGES since 4.2.7.1

To view the changes for each gem, please read the changelogs on GitHub:

Full listing

To see the full list of changes, check out all the commits on GitHub.

SHA-1

If you’d like to verify that your gem is the same as the one I’ve uploaded, please use these SHA-1 hashes.

Here are the checksums for 4.2.8.rc1:

$ shasum *-4.2.8.rc1.gem
cb6ffe33124a95c84598437c3698f016acc30b01  actionmailer-4.2.8.rc1.gem
ed4c50bf4418ec6b82bf17cf41fcd8dd28a4c423  actionpack-4.2.8.rc1.gem
7ccc80e22af39350f0f2d8055663d1adb2320caa  actionview-4.2.8.rc1.gem
7dc4923abcbf3587c5aa6d6cf425ad0e3f69877e  activejob-4.2.8.rc1.gem
b97863c12a06beca60fe0f1e5760fd2e21f0d40d  activemodel-4.2.8.rc1.gem
40e7d2c780f8b0e70adb2a725fb773648539b4fe  activerecord-4.2.8.rc1.gem
edc12197ae5d6e13d6618c40143196ddd5debadd  activesupport-4.2.8.rc1.gem
04849eea3d5c5f20aa51b6dbd31357c9328d10ab  rails-4.2.8.rc1.gem
e05dce3a6c14b36b35bf1ea13433677e867602ae  railties-4.2.8.rc1.gem

As always, huge thanks to the many contributors who helped with this release.

This Week in Rails: Fresh code to fight the Winter doldrums

Hello! This is your host Andy, bringing you another edition of This Week in Rails.

I’m in a cold Northern climate ❄️️ and we’re in the middle of Winter right now. To me, it’s the best time of the year to stay inside and dive into some new code. Let’s take a look at some of the latest changes made to Ruby on Rails in the past week.

This Week’s Rails Contributors

We had 31 contributors this week. There are lots of PRs for bug fixes which are nice to see. Many thanks to all of the contributors!

New

Add warnings option to test runner

This change provides an option to enable Ruby’s warnings in tests.

Improved

Refactor Active Record reflections

This PR refactors reflections such that we can iterate over each reflection and ask the reflection object what scopes should be applied to the query we are currently building.

Report the attribute on ActiveRecord::SerializationTypeMismatch

When a ActiveRecord::SerializationTypeMismatch error occurs, we will now know which attribute caused the error.

Simplify query in column_definitions() for Postgres

This patch updates how column_definitions() for Postgres is calculated. The author has a nice usage of the EXPLAIN tool, to show that the new implementation is more efficient.

Fixes

Reload through_record that has been destroyed

For has_one :through associations, if through_proxy is not reset, setting a new record causes the runtime error Can’t modify frozen hash.

Wrapping up

That’s it from This Week in Rails. There were many other great contributions, too numerous to list here, but feel free to check them out!

Catch you next week!

This Week in Rails: Mailer preprocessing and new ERB handler

Steampunk! It’s all the rage with the kids these days.

Honestly, I was going to work this better into the lead but then I ran out of… ssssstea… 🤓

Anyway friendo! Here’s what Kasper dug up from this week in Rails.

This Week’s Rails Contributors

This week we got 33 committers: welcome or hello again! Either way, you all seem to be on the right track 😉

Action Mailer Preprocessing

Incoming! Mailers can now use params allowing for easier preprocessing with before_action akin to Action Controller. To enable call mailers like this: InvitationMailer.with(invitee: person).account_invitation.deliver_later

See the pull request for a considerable A/B example.

Rails uses Erubi for ERB handling

For many years Rails has used Erubis to handle ERB templates, but it’s been deprecated in favor of Erubi. Being 1/6 shorter to type is far from the only thing Erubi has going for it, so dip into the pull request for the full list 😄

One more thing

Steampunk! It’s hip, it’s wholesome and for the whole family.

Wrapping up

That’s it from This Week in Rails! There were many other great contributions, too numerous to list here, but feel free to check them out!

See ya!

New Action Pack caching gems released

Hi everyone,

I’m happy to announce that new versions of the caching gems extracted from Rails 4.0 have been released.

Action Pack Page Caching (v1.1.0)

CHANGES since 1.0.2

  • Support for Rails 5.0
  • Support for setting page_cache_directory at the controller instance level
  • Support for setting page_cache_directory using a proc, symbol or callable object

To see the full list of changes, check out all the commits on GitHub.

SHA-1

If you’d like to verify that your gem is the same as the one I’ve uploaded, please use this SHA-1 hash.

$ shasum actionpack-page_caching-1.1.0.gem
b9626f7afeb1d69267d1fd6b7255a30be7c33d29  actionpack-page_caching-1.1.0.gem

Action Pack Action Caching (v1.2.0)

CHANGES since 1.1.1

  • Support for Rails 5.0
  • Respect Accept header when caching actions
  • Standardise behavior of options :layout and :cache_path when passed a proc, symbol or callable object

To see the full list of changes, check out all the commits on GitHub.

SHA-1

If you’d like to verify that your gem is the same as the one I’ve uploaded, please use this SHA-1 hash.

$ shasum actionpack-action_caching-1.2.0.gem
308c3acf35c0bdbf15e5c63b64aeda0ec817a269  actionpack-action_caching-1.2.0.gem

Many thanks to the numerous people who have contributed PRs and reported bugs.

This Week in Rails: DB adapters, Git, Action Cable and more!

Hello everyone! This is Roque bringing the latest news from the Rails community.

Remember, today is the last day to submit your RailsConf proposal. You have until 11:59 p.m. MST!

Now, let’s get started!

This Week’s Rails Contributors

This week 33 people contributed to Rails. We also got 4 first time contributors. Welcome aboard folks and keep it going!

SQL Server adapter released for Rails 5

The 5.0.x version of the adapter is only for the latest 5.0 version of Rails. If you need the adapter for an older version of Rails, just install the latest version of the adapter that matches your Rails version (3.2.x to 4.1.x).

Git repo in new Rails projects

New projects will now be generated with a Git repo by default. Please use the option --skip-git if you choose to skip it.

Foreign Key Support for SQLite

Adds foreign key support for SQLite 3.6.19 (or greater) in create statements.

Improved

Improve the AS::NumericWithFormat#to_s memory allocation

Thanks to some good profiling, ActiveSupport::NumericWithFormat#to_s should behave better and not allocate too many objects. 🔎

Fixed

Add channel prefix support to Action Cable Redis adapter

Without channel prefix in Redis, apps using the same Redis server could have their communication compromised. You can now set the option channel_prefix in your cable.yml file. Please check the PR for details.

Make all Rails commands work in engines

The following commands are now working in engines: server, console, dbconsole and runner.

Generate migrations at custom path

New database migrations will be generated at the path set by config.paths["db/migrate"] if the option is defined.

Fix Module#parent_name on a frozen module

The method would throw a runtime error when called for a frozen module.

Wrapping up

That’s it from This Week in Rails! There were many other great contributions, too numerous to list here, but feel free to check them out!

Until next week!

This Week in Rails: Time, Duration fixes and more

Happy new year (yet again) ! And a Friday the 13th 👻

This is Vipul, bringing you the latest from just the second week of the year, which is shaping to be really busy.

Thanks to all the 27 contributors, in particular to the 4 people who contributed for the first time. Keep up the good work!

Here are the most relevant changes to Rails master for this week.

Improved

Constant look-up would no longer fall back to top-level constant since Ruby 2.5

Since top-level constant lookup has been removed on Ruby 2.5, Rails takes care of relevant changes on its side, so that we rely on properly scoped constants, instead of relying on fallback lookup.

Fixed

Fix pool_from_any_process to use most recent specification

If a process is forked more than once, the Active Record connection pool was grabbing the oldest connection specification for a process, and not the most recent one.

This issue is not seen for single processes, but if you are forking the process multiple times, the wrong specification will be returned and incorrect connection will be used.

This change fixes the issue by reversing the list of specification names so we can grab the most recent one rather than the oldest.

Make time travel work with subclasses of Time/Date/Datetime

Previously when using time travel methods, travel_to, etc, and calling now on a subclass of e.g. Time, it would return an instance of Time instead of returning an instance of the subclass.

This change fixes the way we return the instance, so that we always return using the correct class.

Fix inconsistent parsing of Durations with both months and years

Previously the following code may fail or succeed depending on the current time.

ActiveSupport::Duration.parse(2.months.iso8601) == 2.months  
ActiveSupport::Duration.parse(3.years.iso8601) == 3.years

This change fixes the inconsistent parsing so that this comparison no longer fails.

Removed

Deprecate reflection class_name option to accept a class

The idea of class_name as an option of reflection is that passing a string would allow us to lazy autoload the class.

Using the class directly, with something like

belongs_to :client, class_name: Customer

is eagerloading models more than necessary and creating possible circular dependencies.

This option is now deprecated, pass strings of the class names instead.

Wrapping up

That’s it from Vipul . I hope you enjoyed this issue. 

If you haven’t already, start working on those RailsConf proposals, you have only 6 days left to submit a good talk!

This Week in Rails: Starting the year with over 100 commits

Happy new year! How was your holiday break? Did you receive nice presents? In case you missed it, Ruby 2.4.0 was released on Christmas day so if you haven’t done it yet… rbenv install 2.4.0 right now!

The first week of 2017 has seen more than 100 commits to rails/rails. Congratulations to all the 32 contributors, in particular to the 8 people who contributed for the first time. Keep up the good work!

Here are the most relevant changes to rails master for this week.

New

Allow to set custom content type for email attachments

With Action Mailer it’s now easy to specify the content type of your attachments. E.g.: mail(body: "\<h1\>Hello\</h1\>", content_type: "text/html").

Added option to ActiveRecord::CounterCache methods

You can now ask Active Record to update specific timestamp columns when incrementing, decrementing, resetting, or updating counter caches.

Default Rails.env to development when missing

If your app does not set RAILS_ENV or RACK_ENV then the value of Rails.env will fall back to development rather than just being an empty string.

Improved

Improve Array#sum with Ruby refinements

Array#sum was defined in Rails with a monkey-patch. Ruby 2.0 introduced refinements for better encapsulation. This is the first PR where they are being used in rails/rails.

Ensure Rails 4.2 works with Ruby 2.4

Some tests and code have been fixed and backported to 4-2-stable so that running Rails 4.2 on Ruby 2.4 will not raise any error. 

Change return value of duplicable?

In Ruby 2.4, NilClass, FalseClass, TrueClass, Symbol and Numeric all support dup. For consistency, duplicable? will now return true for all these classes.

Fixed

Serialize JSON attribute value nil as SQL NULL

The way in which a nil JSON payload is stored in a database was inadvertently changed in Rails 5.0. This fix maps nil to SQL NULL, exactly as how it was in Rails 4.x.

Fix generator command for nested namespaced rails engines

If the name of your Rails engine has a hyphen then this PR (fixing the path of namespaced controllers) is for you! 

Update cookies helper on all HTTP requests

This fixes a regression by which cookies were only updated on GET requests. Now we will update the helper for all requests.

Removed

Remove support for MySQL

MySQL 5.0 reached “end of life” more than five years ago. Rails now requires at least version 5.1.10.

Remove previously deprecated code

By now, you should have already dropped any reference to Rake’s db:test:clone, Configuration’s serve_static_files and static_cache_control and ActiveRecord’s uniq, uniq!, uniq_value, insert_sql, update_sql, delete_sql.

Wrapping up

That’s it from Claudio. I hope you enjoyed this issue. And now… let me go back to writing my RailsConf proposal… I only have 14 days left to submit a good talk!

See you all in Phoenix at the end of April!

[ANN] Rails 5.0.1 has been released!

Hi everyone,

I am happy to announce that Rails 5.0.1 has been released.

CHANGES since 5.0.0

To view the changes for each gem, please read the changelogs on GitHub:

Full listing

To see the full list of changes, check out all the commits on GitHub.

SHA-1

If you’d like to verify that your gem is the same as the one I’ve uploaded, please use these SHA-1 hashes.

Here are the checksums for 5.0.1:

$ shasum *-5.0.1.gem
51a4112d989f9658c995ac0ef93a9d8dc9e7d1ff  actioncable-5.0.1.gem
839aa492e3d81568b9d5c4c9f2974a3964e12025  actionmailer-5.0.1.gem
240394cb1422317a6d2e4cfa057d2c5bf6c96c5a  actionpack-5.0.1.gem
c52c66c8c6a7f8af8e4912a9e4d1711eb8f8daff  actionview-5.0.1.gem
223ff0c1235c6d139707b623790eb00b39ef6c84  activejob-5.0.1.gem
9aeabd9d02f982c010bd59c3db9774d95494177b  activemodel-5.0.1.gem
ad285d6723c2d51df852b372b20b4f8a061ccbf6  activerecord-5.0.1.gem
5c546eca785ea25624b5a80f0304fbac9f2efe44  activesupport-5.0.1.gem
f9c5beee8106f3266937248058f676a7d0d8b44e  rails-5.0.1.gem
a8c264bccbad342e8e781a3fffab98466f3e4852  railties-5.0.1.gem

As always, huge thanks to the many contributors who helped with this release.