ruby-on-railsactivesupportactivesupport-concernelasticsearch-rails

rails undefined method at module


i have a method in my rails module, this is my module

  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. when i'am trying to execute this method(setting_index) at first time i got an error. enter image description here

but then when i'am trying to execute again this error is gone..enter image description here

can anyone solve this and give me a clear answer... thanks for your concern :)


Solution

  • 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
    

    I think you need to put included module outside included do block.