加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – ActiveStorage生成附件网址

发布时间:2020-12-17 01:57:33 所属栏目:百科 来源:网络整理
导读:我曾尝试将ActiveStorage与一个附件一起使用.我能够上传附件. 我的问题是生成URL.我正在使用url_for class Template ApplicationRecord acts_as_archival readonly_when_archived: true before_archive belongs_to :user has_many :fields,dependent: :destr
我曾尝试将ActiveStorage与一个附件一起使用.我能够上传附件.

我的问题是生成URL.我正在使用url_for

class Template < ApplicationRecord
  acts_as_archival readonly_when_archived: true

  before_archive

  belongs_to :user

  has_many :fields,dependent: :destroy
  accepts_nested_attributes_for :fields,allow_destroy: true

  has_many :contracts
  has_one_attached :image

end

<%= url_for(@template.image) %>

我有这个错误

undefined method `active_storage_attachment_path' for
#<#<Class:0x007fa1de477520>:0x007fa1defa8b88>

解决方法

你可以尝试使用

@template.image.url

资料来源:http://www.rubydoc.info/gems/activestorage/0.1

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读