rails模块上的undefined方法

时间:2017-08-07 07:08:34

标签: ruby-on-rails activesupport activesupport-concern elasticsearch-rails

我的rails模块中有一个方法,这是我的模块

  module Searchable
  extend ActiveSupport::Concern

  included do
    include Elasticsearch::Model
    include Elasticsearch::Model::Callbacks
    index_name Rails.application.class.parent_name.underscore
    puts Rails.application.class.parent_name.underscore
    document_type self.name.downcase

    # you get an error if this shit run first
    module ClassMethods
      def setting_index(arguments)
        settings index: {number_of_shards: 1} do
        ... more code ...

顺便说一句。当我第一次尝试执行此方法(setting_index)时出现错误。 enter image description here

但是当我再次尝试执行时,此错误消失了...... enter image description here

任何人都可以解决这个问题并给我一个明确的答案...... 谢谢你的关心:))

1 个答案:

答案 0 :(得分:0)

require 'active_support/concern'

module Callable
  extend ActiveSupport::Concern
  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks

  included do
  end

  module ClassMethods
      def setting_index(arguments)
        settings index: {number_of_shards: 1} do
        ... more code ...

  end
end

我认为您需要将包含的模块放在包含do块之外。

相关问题