简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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