17
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails4.0でついたconcernsフォルダをRails3.2に作る

Last updated at Posted at 2013-03-14

小ネタですが、Rails3.2系でもcontrollerやmodelに関係するconcern系をまとめられると嬉しいので作って見ることにします。

ディレクトリの作成

# Rails.root に移動しシェルにて
# Rails4.0では .gitkeep から .keepになってる。。 
# どうもmercurialでも対応できるように?
# そういうわけでこちらでも.keepにする
mkdir -p app/controllers/concerns
touch    app/controllers/concerns/.keep
mkdir -p app/models/concerns
touch    app/models/concerns/.keep

config/application.rbの自動ロードに追加

application.rb
config.autoload_paths                  += %W(
      #{config.root}/app/controllers/concerns
      #{config.root}/app/models/concerns
      #{config.root}/lib
    )

これでmodels, controllers以下にconcernsフォルダができ、activesupport::concern系のいい置き場がてにはいった!

あと、concerns以下は名前空間がグローバルなので(Rails 4.0も)適当にフォルダを掘ってもいいかもしれないですね。

17
18
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
17
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?