####
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.
43 people helped make Rails even awesome this week. Checkout the pulse page for more details.
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!
Active Record now supports specifying a collation function for SQLite string columns.
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.
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!)
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.
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 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!