我使用的是 Ruby 2.4.1-rc2 和 Rails 5.2.1,并且正在使用主动存储。文件上传非常完美,但是当我尝试使用 rails_blob_path(user.avatar, disposition: "attachment", only_path: true)
或 Rails.application.routes.url_helpers 调用文件下载 url 时.rails_blob_path(c.allegati, only_path: true)
,它给了我这个错误:
NoMethodError at /profilepage
undefined method `signed_id' for #<ActiveStorage::Attached::Many:0x00007f85c90dd170>
0x00007f85c90dd170 每次重新加载时都会更改。
我在此处和 Google 上进行了搜索,但没有人遇到此问题,我的 ActiveStorage 配置是标准配置(S3 凭据除外)。
有什么想法吗?提前致谢。
编辑:更多代码
show.html.erb
<% if @utente.sostitutore == "1" %>
<h1 class="title is-3">Sostituzioni accettate</h1>
<% b = Sostituzione.where(sostitutore: utente_corrente.id) %>
<% if b.empty? %>
<p>
Nessuna sostituzione accettata
</p>
<br />
<% else %>
<% b.each do |c| %>
<%= Rails.application.routes.url_helpers.rails_blob_path(c.allegati, only_path: true) %>
<% end %>
<% end %>
<% end %>
型号
class Sostituzione < ApplicationRecord
attr_accessor :termini
has_many_attached :allegati
has_many_attached :documentiudienza
end
Edit2:尽管上传正确,但调试结果为空。
已解决
最佳答案
解决了!对于多个附件(意大利语的 allegati),有 @sostituzione.allegati.first 等。 我用这段代码解决了:
<% @sostituzione.allegati.each do |allegato| %>
<div class="level">
<%= link_to 'Scarica documento allegato', rails_blob_path(allegato, only_path: true), class: 'button is-primary is-big' %>
</div>
<% end %>
关于ruby-on-rails - Rails:#<ActiveStorage::Attached::Many:casualID> 的未定义方法 `signed_id',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52046957/