附加图像未显示在导轨上

问题描述

我有一个“短”模型如下:

class Short < ApplicationRecord
  belongs_to :director
  belongs_to :composer
  has_one_attached :clip
  has_one_attached :thumbnail
end

我正在播种:

curta1 = Short.new()
curta1.name = "FortePiano"
curta1.launch = Date.today()
curta1.datasheet = "Eu sou um curta!"
curta1.director = director1
curta1.composer = composer1

curta1.save
curta1.thumbnail.attach(io:File.open(Rails.root + "app/assets/images/download.jpeg"),filename: 'download.jpeg')

但是,当我尝试在这样的视图中显示缩略图时:

<% @shorts.each do |short| %>
  <div class="col-lg-4">
    <%= main_app.url_for(short.thumbnail) %>
    <%= link_to (short.name + " - " + short.launch.strftime("%Y")),short %>
  </div>
<% end %>

我收到此错误undefined method `attachment_url' for #<Actiondispatch::Routing::RoutesProxy:0x00007f90e68c0e00>

我已经测试过运行 short.thumbnail.attached? 并返回 true

谁能帮我正确显示缩略图

使用 Rails 6.1.3.2

PS:如果我使用

<%= image_tag(short.thumbnail) %>

它返回我Can't resolve image into URL: undefined method `attachment_url' for #<ActionView::Base:0x007f90e689e7b0>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)