我正在学习 ruby on rails 4,并希望在 ActiveSupport 中使用关注。这是我的做法:
控制器/关注点/do_things_controller.rb
# file controllers/concerns/do_things_controller.rb
require 'active_support/concern'
module DoThings
extend ActiveSupport::Concern
def do_something
puts 'something'
end
included do
helper_method :do_something
end
end
控制器/application_controller.rb
# file controllers/application_controller.rb
class ApplicationController < ActionController::Base
require 'concerns/do_things_controller'
include DoThings
end
在views/layouts/application.html.haml我调用do_something,它显示错误:
undefined method `do_something'
谢谢