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