简体   繁体   English

Rails-在模块上包括elasticsearch吗?

[英]Rails - Include elasticsearch on module?

Is it possible to have the 是否有可能

include Elasticsearch::Model
include Elasticsearch::Model::Callbacks

on a module? 在模块上? and how so? 怎么会这样呢?

You may use included block of ActiveSupport::Concern to include these modules 您可以使用ActiveSupport :: Concern的 included块来包含这些模块

Something like: 就像是:

module MyElasticSupport
  extend ActiveSupport::Concern

  included do
    include Elasticsearch::Model
    include Elasticsearch::Model::Callbacks
  end

  ... some other code ...
end

class MyModel
  include MyElasticSupport

  ... some other code ...
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM