Your module does not autoload (at least not in 3.2.6). You must download it explicitly. You can achieve this with the following line of code
# in application.rb config.autoload_paths += %W(
You can check startup paths using Rails.application.config.autoload_paths
. Maybe it is really specific to you?
Now you are sure that your module is loaded, you can check it in the rails console
by calling
> Functions::FormHelper
Now you cannot use this module as a default view helper. Use #included
to determine the helper when your module is turned on. Thus, you achieve a "lazy assessment." I think the problem with your code is that the helper
method is called before the module is turned on. (someone should correct me if I am wrong)
Here is the code:
Module Functions Module FormManager def error_message() ... end def self.included m return unless m < ActionController::Base m.helper_method :error_message end end end
You should also remove the helper
line from your controller.
EDIT:
You can achieve this without startup. Just use require "functions/form_manager"
. You define helper_method for each method. If you want to use all methods of the module as helpers, use
def self.included m return unless m < ActionController::Base m.helper_method self.instance_methods end
EDIT2:
It seems you do not need to use self.included
. This provides the same functionality:
class ApplicationController < ActionController::Base include Functions::FormManager helper_method Functions::FormManager.instance_methods end
shime source share