upinetree's memo

Web系技術の話題や日常について。

Rails 5.0.1 の変更点で個人的に気になったところ雑まとめ

先日12/21に Rails 5.0.1 が出ましたね。 CHANGELOG をざっと読みながら、個人的に気になったところを雑にまとめます。 雑まとめなので間違ってるかもしれません。正確な情報はリンク先を見てください〜。

3行で

ActionCable

https://github.com/rails/rails/blob/v5.0.1/actioncable/CHANGELOG.md

ActionPack

https://github.com/rails/rails/blob/v5.0.1/actionpack/CHANGELOG.md

  • Add ActionController::Parameters#merge!, which behaves the same as Hash#merge!.
  • Added ActionController::Parameters#deep_dup which actually creates a params copy, instead of refereing to old references in params.
  • Add to_param to ActionController::Parameters deprecations.
    • AC::Parameters がHash継承しなくなった影響でto_paramsが従来の期待通りに動かなくなった(AC::Parametersを返す)
    • to_h してから to_param 使ってくれとのこと
    • https://github.com/rails/rails/pull/26328
  • SSL: Changes redirect behavior for all non-GET and non-HEAD requests
    • force-sslしてるときにPOSTとかするとGETでリダイレクトされてたど、それだと別のアクションを呼び出すことになるのでPOSTでリダイレクトするよ
    • そうしたときにステータスコードも適切なものに変えたよ
  • Deprecated omitting the route path. Specify the path with a String or a Symbol instead.
  • Added new ActionDispatch::DebugLocks middleware that can be used to diagnose deadlocks in the autoload interlock

ActionView

https://github.com/rails/rails/blob/v5.0.1/actionview/CHANGELOG.md

  • Render now accepts any keys for locals, including reserved words
    • renderに予約語もlocalとして渡せるようになった。local_assigns[:class]のようにして参照する
  • Changed partial rendering with a collection to allow collections which implement to_a.
    • Collection Rendering として Enumerable ならなんでも渡せるようになった

ActiveJob

https://github.com/rails/rails/blob/v5.0.1/activejob/CHANGELOG.md

  • Added instance variable @queue to JobWrapper.
    • rescue-scheduler への対応だけど、もしかしたらsidekiqとかでも便利になる?

ActiveRecord

https://github.com/rails/rails/blob/v5.0.1/activerecord/CHANGELOG.md

  • バグフィックスたくさん。特に複数スレッドでうまく動くようにしてるのが多い(クエリキャッシュとかコネクションプーリングとか)
  • Introduce Model#reload_ to bring back the behavior of Article.category(true) where category is a singular association.
    • article.reload_categoryのようにして特定のhas_one関連だけリロードできるようになった
    • 今までhas_one関連については article.category(true)でリロードできてたけど、それがRails5でdeprecatedになっていた。article.reload.categoryでは完全な代替にはならない(未保存の他の関連インスタンスの変更が消えるとか)という背景があった
    • https://github.com/rails/rails/pull/27133
  • Always store errors details information with symbols.
    • autosaveでバリデーションエラーが発生したときに保存するためのkeyをSymbolにした
    • いままではStringだったけどそれだとエラーを保存する他の処理でSymbolにしているのでずれてて扱いづらい
    • 場合によっては breaking change になるかもだけどほとんどのケースは大丈夫かな
    • https://github.com/rails/rails/pull/26552
  • Avoid loading records from database when they are already loaded using the pluck method on a collection.
    • 地味に嬉しい。reload考慮する必要ありそう?
  • Doing count on relations that contain LEFT OUTER JOIN Arel node no longer force a DISTINCT. This solves issues when using count after a left_joins.
    • むしろいままでDISTINCTだったのか

ActiveSupport

https://github.com/rails/rails/blob/v5.0.1/activesupport/CHANGELOG.md

  • サマータイム系のバグフィックスが多い
  • Fix thread_mattr_accessor subclass no longer overwrites parent.
    • 親と子で別々に属性持てるようになった

Railtile

https://github.com/rails/rails/blob/v5.0.1/railties/CHANGELOG.md

  • バグフィックスだけ