Rails - view the image after viewing the file through Active Storage

I have a project that is on rails 5.1.2, and I'm trying to implement Active Storage on it, after several online learning online, I can set up Active Storage, and I can see that the data is stored inside active_storage_blobsand active_storage_attachments.

I also confirmed the launch user.avatar.attached?, and in response I realized that everything was working.

I have a problem displaying the image in the field of view, I tried

<%= image_tag(url_for(user.avatar)) %>

NoMethodError: undefined method `active_storage_attachment_path '

What I did to configure Active Storage

Run the install command

rails active_storage:install

This gave an error. I don’t know how to create an active_storage task: install '

but the next team worked

rails activestorage:install

I added gem 'activestorage'insidegemfile

, storage_services.yml

test:
  service: Disk
  root: <%= Rails.root.join("tmp/storage") %>

local:
  service: Disk
  root: <%= Rails.root.join("storage") %>

development.rb

config.active_storage.service = :local

User has_one_attached :avatar

user.avatar.attach(params[:user][:avatar])
  • , ,
  • , root

,

? , ?

NoMethodError: undefined `active_storage_attachment_path '

+4
1

config/appication.rb, :

require "active_storage/engine"

5.2 beta, Active Storage. , . 5.1 5.2, . http://edgeguides.rubyonrails.org/5_2_release_notes.html. , , .

0

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


All Articles