【发布时间】:2021-08-21 13:37:50
【问题描述】:
这是我的模型的样子。
class Bug < ApplicationRecord
has_many :bug_users, dependent: :destroy
has_many :users , through: :bug_users
belongs_to :project
has_one_attached :screenshot
end
上传部分工作得很好,但是当我在这样的视图中显示它时
<% @bugs.each do |bug| %>
<p>
<strong>Title:</strong>
<%= bug.title %>
</p>
<p>
<%if bug.screenshot.present? %>
<strong>Screenshot:</strong>
<%= image_tag bug.screenshot %>
<%end%>
</p>
<% end%>
【问题讨论】:
-
试试:
<%= image_tag url_for(bug.screenshot) %> -
现在给出:#<:base:0x0000000000c0a8> 的未定义方法 `attachment_path'
-
也许
bug.screenshot.attached?返回 false。 -
@LamPhan nah 我试过没有 if 语句它仍然给出同样的错误:(
标签: javascript ruby-on-rails ruby web rails-activestorage