Search code examples
ruby-on-railsrubyrails-activestorage

Rails: undefined method `signed_id' for #<ActiveStorage::Attached::Many:casualID>


I'm on Ruby 2.4.1-rc2 and Rails 5.2.1 and I'm using active storage. File uploading is perfect, but when I try to recall a file download url with rails_blob_path(user.avatar, disposition: "attachment", only_path: true) or Rails.application.routes.url_helpers.rails_blob_path(c.allegati, only_path: true), it gives me this error:

NoMethodError at /profilepage
undefined method `signed_id' for #<ActiveStorage::Attached::Many:0x00007f85c90dd170>

0x00007f85c90dd170 changes everytime I reload.

I searched here and on Google but no one has this issue, my ActiveStorage config is the standard config (except for S3 credentials).

Any ideas? Thanks in advance.

Edit: more code

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 %>

model

class Sostituzione < ApplicationRecord
   attr_accessor :termini
   has_many_attached :allegati
   has_many_attached :documentiudienza
end

Edit2: it resultes via debug empty despite it's being uploaded correctly.

Solved


Solution

  • Solved! For multiple attachments (allegati in italian) there is @sostituzione.allegati.first etc. I solved with this code:

    <% @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 %>