无法从包含的模块访问方法

时间:2013-09-20 17:40:48

标签: ruby-on-rails

我正在使用rails 4学习ruby,并希望在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'

由于

0 个答案:

没有答案