我的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)时出现错误。
任何人都可以解决这个问题并给我一个明确的答案...... 谢谢你的关心:))
答案 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块之外。