This Week in Rails

September 2, 2022

Bugfixes, improvements and more!

Hi, this is Greg with the latest news from the world of Rails.

Return "Range Not Satisfiable" return code for partial downloads with incorrect range
This PR fixes an issue when a partial download request with an incorrect range was made. Before the fix, Rails threw a RoutingError, but from now on it returns a "Range Not Satisfiable" return code.

Allow ActiveRecord::QueryMethods#select to accept a hash
If you prefer hashes over raw SQL strings, now you can use them with select when you join tables. For instance:
Post.joins(:comments).select(
  posts: { id: :post_id, title: :post_title },
  comments: { id: :comment_id, body: :comment_body}
)

Pass options accessor to Cache#fetch block
With this change, it is possible to pass cache options to the fetch method, so if you use 3rd party auth tokens and store them in the cache, you can set the cache expiry time to the same as the token's:
Rails.cache.fetch("3rd-party-token") do |name, options|
  token = fetch_token_from_remote
  # set cache's TTL to match token's TTL
  options.expires_in = token.expires_in
  token
end

Update guides for update_all
The outdated description of ActiveRecord#update_all in the Rails guides has been updated.

29 people contributed to Rails since last week!

Thanks for reading, until next week!