LoginSignup
3
0

More than 1 year has passed since last update.

はじめに

Ateam Group U-30 Advent Calendar 2022の18日目は、 @mayobimu が担当します!

Module#concerningとは

Rails 4.1.0で追加された機能
Rails 4.0で追加されたActiveSupport::Concernをより使い方の幅を広めることができる

何が変わったの?

ActiveSupport::Concernの場合

  • app/models/concerns/orapp/controllers/concerns/からincludeする必要がある

Module#concerningの場合

  • 同じmodelsファイルからincludeできる、1つのファイルで完結できる
  • 複数の場所で使用するならActiveSupport::Concern、分離したいだけならModule#concerningを使用するのが良さそう?

# app/models/host.rb
class Host
  include M
end

class Host
  concerning :M do
      included do
        scope :disabled, -> { where(disabled: true) }
      end
  end
end

参考

さいごに

Ateam Group U-30 Advent Calendar 2022はまだまだ続きます!ぜひ購読登録して、明日以降の記事もチェックしてみてください!

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0