LoginSignup
15
12

More than 5 years have passed since last update.

concernsの名前空間(ディレクトリ)を分けた場合のファイルの置き場所

Posted at

例えば

  • app/controllers/foo/users_controller.rb

みたいな感じでファイルを作って、ここにconcernsを作りたい場合

  • app/controllers/concerns/foo/users_concern.rb

というようにファイルを作り、モジュールには

module Foo::UsersConcern
  extend ActiveSupport::Concern
...

end

というように書けば、

module Foo
  class UsersController
    include UsersConcern

    ...

  end
end

というように呼べる。

最初、

  • app/controllers/foo/concerns/users_concern.rb

みたいな感じで作っちゃってちょっと嵌った。

15
12
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
15
12