Rails эластичный поиск: магазин URL-адрес изображения скрепки - PullRequest
0 голосов
/ 06 декабря 2018

Я хотел бы хранить URL-адреса изображений непосредственно в моих записях эластичного поиска, чтобы программе не нужно было совершать другие вызовы через ActiveRecrods.Однако у меня проблема с импортом этих ссылок.Мой код:

class Lead < ApplicationRecord
...
 has_attached_file :product_image, styles: { default: "650x400>", thumb: "150x120>" },
  default_url: "/images/:style/default_product_image.png"
  validates_attachment_content_type :product_image, content_type: /\Aimage\/.*\z/
end

Отображение:

settings index: { number_of_shards: 1 } do
        mappings dynamic: false do
          indexes :id, type: 'long'
          indexes :lead_status, type: 'keyword'
          indexes :country, type: 'keyword'
          indexes :city, type: 'keyword'
          indexes :title, analyzer: 'english', index_options: 'offsets'
          indexes :description_short, type: 'keyword'
          indexes :created_at, type: 'date'
          indexes :category do 
            indexes :name, type: 'keyword'
          end
          indexes :user do
            indexes :user_name, type: 'keyword'
            indexes :id, type: 'long'
          end
        end
     end

      #includes relations to elasticsearch indexed model
      def as_indexed_json(options = {})
        self.as_json(
          options.merge(
            only: [:id, :lead_status, :city, :title, :description_short, :created_at,
                :country, :product_image_file_name],
            include: { 
                category: { only: :name },
                user: { only: [:user_name, :id] },
                image: product_image.url // here is my url 
            }   
          )
        )
      end

Попытка вызвать "Lead.import" на моей консоли рельсов дает мне эту ошибку:

Traceback (most recent call last):
        2: from (irb):2
        1: from app/models/concerns/searchable.rb:80:in `as_indexed_json'
NoMethodError (undefined method `image' for #<Lead:0x00007ff7f447b820>)

Какя могу это исправить?

...