Last active
September 21, 2018 02:57
-
-
Save d-shimizu/6567961 to your computer and use it in GitHub Desktop.
Railsでのモジュールのオートロード ref: http://qiita.com/d_shimizu/items/4affe530d541db56e937
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… | |
module TestApp | |
class Application < Rails::Application | |
… | |
### モジュール自動ロードPathの指定を追記 | |
config.autoload_paths += %W(#{config.root}/lib) | |
… | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestController < ApplicationController | |
### モジュールの読み込み(インクルード) | |
include Hoge | |
… | |
def index | |
… | |
### indexメソッド内でHogeモジュールの「test_module_method」メソッドを実行 | |
test_module_method | |
… | |
end | |
… | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Hoge | |
def test_module_method | |
処理内容 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment