Rails:#<activestorage :: attached :: many:casualid>的未定义方法`signed_id'

时间:2018-08-27 21:05:16

标签: ruby-on-rails ruby rails-activestorage

我正在使用Ruby 2.4.1-rc2和Rails 5.2.1,并且正在使用活动存储。文件上传是完美的,但是当我尝试使用rails_blob_path(user.avatar, disposition: "attachment", only_path: true)Rails.application.routes.url_helpers.rails_blob_path(c.allegati, only_path: true)调用文件下载URL时,会出现以下错误:

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 :尽管已正确上传,它还是通过调试结果为空。

已解决

1 个答案:

答案 0 :(得分:0)

解决了!对于多个附件(意大利语中的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 %>