ruby-on-rails - Rails:未定义的方法 `signed_id' 用于#
问题描述
我在 Ruby 2.4.1-rc2 和 Rails 5.2.1 上,并且正在使用活动存储。文件上传是完美的,但是当我尝试使用rails_blob_path(user.avatar, disposition: "attachment", only_path: true)
or调用文件下载 url 时Rails.application.routes.url_helpers.rails_blob_path(c.allegati, only_path: true)
,它给了我这个错误:
NoMethodError at /profilepage
undefined method `signed_id' for #<ActiveStorage::Attached::Many:0x00007f85c90dd170>
0x00007f85c90dd170 每次重新加载时都会更改。
我在这里和谷歌上搜索过,但没有人有这个问题,我的 ActiveStorage 配置是标准配置(S3 凭据除外)。
有任何想法吗?提前致谢。
编辑:更多代码
显示.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 %>
推荐阅读
- vue.js - apollo 客户端,在不破坏使用 jwt 的 http 链接的同时添加订阅
- github - 我可以在私有 git 存储库中授予不同的权限吗?
- if-statement - 否则如果在第一次迭代时停止 [Arduino]
- removing-whitespace - 删除除制表符和换行符以外的所有空格
- javascript - 如何使用 CSS 动态重新定位画布元素
- javascript - Webpack 无法编译 sass - 模块解析失败:意外字符 '@' (1:0)
- android - (Android) onNavigationItemSelected 方法未被调用
- javascript - 在进入下一页之前单击鼠标后,在 div 中运行脚本
- python - py2app 遇到问题
- javascript - 如何遍历具有特定条件的对象并返回其值的数组?