elasticsearch-rails: index_name STI inheritance problem

The behavior of Class.index_name is not as expected when using concerns and STI:

module Searchable
  extend ActiveSupport::Concern
  included do
    include Elasticsearch::Model
    index_name "app_name-#{Rails.env}-#{table_name}"
  end
end

class Post < ActiveRecord::Base
  include Searchable
end

class Post::News < Post; end

puts Post.index_name
=> "appname-development-posts" [OK]
puts Post::News.index_name
=> "post-news" [Expected: "appname-development-posts"]

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 15 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Hmm, setting it on each model seems error prone to me. I also tried to simply override the method in the included block:

def self.index_name; … ; end

This worked fine in the console when calling MyClass.index_name, but on indexing it was ignored.