"300-6ren">
gpt4 book ai didi

ruby-on-rails - 如何从ElasticSearch模型索引中获取image.url

转载 作者:行者123 更新时间:2023-12-02 23:05:35 25 4
gpt4 key购买 nike

有人知道如何从用Elasticsearcg索引的图像(使用轮胎)中获得image.url吗?

class Photo < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
attr_accessible :caption, :user_id, :image, :venue_id
attr_accessible :id, :image_file_name, :created_at, :updated_at, :city, :state, :country, :image_url
has_attached_file :image, :styles => { :large => "9999x9999", :medium => "300x200>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
end

class SearchController < ApplicationController
def index
city_name = params[:city]
@photos = Photo.search city_name
respond_to do |format|
format.html # index.html.erb
end
end

结束

在我的index.html.erb中,当我这样做时:
<% @photos.each do |photo| %>
<%= image_tag photo.image.url(:medium) %>

我收到nil:NilClass的未定义方法“url”

有谁能够帮助我 ?

非常感谢你

最佳答案

添加到您的照片模型:

mapping do
indexes :image
end

def image
picture.url(:medium)
end

在您看来
<%= image_tag photo.image %>

关于ruby-on-rails - 如何从ElasticSearch模型索引中获取image.url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15867623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com