ActiveStorage generates a join URL

I tried using ActiveStoragewith one attachment. I was able to download the attachment.

My problem is creating the url. I useurl_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) %>

I have this error

undefined method `active_storage_attachment_path' for
#<#<Class:0x007fa1de477520>:0x007fa1defa8b88>
+4
source share
2 answers

You can try using

@template.image.url

Source: http://www.rubydoc.info/gems/activestorage/0.1

0
source

I'm sure you are on the old stone before it merged with Rails. If you do

bundle show activestorage

I think he will say that you are using gems / activestorage -0.1

Try connecting rails:

gem 'rails', git: 'https://github.com/rails/rails.git'

, , .

0

Source: https://habr.com/ru/post/1685158/


All Articles