0

未定义的方法我在我的轨道模块的方法,这是我的模块轨在模块

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 ... 

BTW。当我试图在第一次执行这个方法(setting_index)时出现错误。 enter image description here

但后来当我'尝试再次执行这个错误消失.. enter image description here

任何人都可以解决这个问题,并给我一个明确的答复...... 感谢您的关注:)

回答

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 

我觉得你需要把包含的模块外面包括做块。

+0

thx its worked :) – cahyowhy