This week in Rails: Enumerable#pluck, SQLite Collation and lots more

#

Hello everyone!

This is Vipul , happily reporting from a Simmering Summer 😎. Pour yourself a drink 🍹, sit back, relax and enjoy, as we go through these hot off the press changes.

This week’s Rails Contributors

43 people helped make Rails even awesome this week. Checkout the pulse page for more details.

New Stuff

Enumerable#pluck

Enumerable#pluck has just landed on master, providing similar functionality as Active Record’s #pluck.

This allows for something like [{ name: "David" }, { name: "Rafael" }, { name: "Aaron" }].pluck(:name) to get everyone’s names. Pretty handy!

Improved

Collation support in SQLite

Active Record now supports specifying a collation function for SQLite string columns.

Default procs in Attributes API

With the new Attributes API, it is now possible to specify a proc as the default values for an attribute, which allows for runtime-generated default values such as attribute :year, :integer, default: -> { Time.now.year }. See also these related changes.

Preserve MySQL’s sql\_mode with strict: :default

By default, Rails overrides MySQL’s sql_mode setting with sql_mode=STRICT_ALL_TABLES to prevent silent data loss. While this is helpful, it has the unfortunate side-effect of overriding any user customizations.

If you prefer to manage this yourself, you can now specify strict: :default in your connection’s config and Rails will leave your sql_mode alone. (STRICT_ALL_TABLES is still highly recommended though!)

Deprecated

Deprecate render nothing: true

If you are using render nothing: true, you should start replacing it with head :ok, which does the same thing and is more semantic. This option will go away permanently in Rails 5.1.

Deprecate Relation#uniq

The superficial similarity between Relation#uniq and Array#uniq has been a source of confusion, which led to the addition of Relation#distinct which better communicates what is happening under the hood.

The recent discussion on #20198 put the final nail in the coffin for Relation#uniq and its friends, #uniq! and #uniq_value. These methods are deprecated and scheduled for removal in Rails 5.1, so you might want to start using #distinct, #distinct! and #distinct_value soon.

That’s a wrap

That’s all for This week in Rails. As always, there are many more changes than we have room to cover here, but feel free to check them out yourself!

P.S. If you enjoyed this newsletter, why not share it with your friends? :) If you wish to be part of this project please don’t hesitate to contact Godfrey – there’re a lot of ways you could help make this newsletter more awesome!