mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix file missing in activestorage's example code [ci skip]
* File.open("~/face.jpg") raise error: `Errno::ENOENT: No such file or directory @ rb_sysopen - ~/face.jpg`
This commit is contained in:
parent
bf206dc2fc
commit
7d14bda3a7
3 changed files with 3 additions and 3 deletions
|
@ -24,7 +24,7 @@ class User < ApplicationRecord
|
|||
end
|
||||
|
||||
# Attach an avatar to the user.
|
||||
user.avatar.attach(io: File.open("~/face.jpg"), filename: "avatar.jpg", content_type: "image/jpg")
|
||||
user.avatar.attach(io: File.open("/path/to/face.jpg"), filename: "face.jpg", content_type: "image/jpg")
|
||||
|
||||
# Does the user have an avatar?
|
||||
user.avatar.attached? # => true
|
||||
|
|
|
@ -17,7 +17,7 @@ module ActiveStorage
|
|||
#
|
||||
# document.images.attach(params[:images]) # Array of ActionDispatch::Http::UploadedFile objects
|
||||
# document.images.attach(params[:signed_blob_id]) # Signed reference to blob from direct upload
|
||||
# document.images.attach(io: File.open("~/racecar.jpg"), filename: "racecar.jpg", content_type: "image/jpg")
|
||||
# document.images.attach(io: File.open("/path/to/racecar.jpg"), filename: "racecar.jpg", content_type: "image/jpg")
|
||||
# document.images.attach([ first_blob, second_blob ])
|
||||
def attach(*attachables)
|
||||
attachables.flatten.collect do |attachable|
|
||||
|
|
|
@ -18,7 +18,7 @@ module ActiveStorage
|
|||
#
|
||||
# person.avatar.attach(params[:avatar]) # ActionDispatch::Http::UploadedFile object
|
||||
# person.avatar.attach(params[:signed_blob_id]) # Signed reference to blob from direct upload
|
||||
# person.avatar.attach(io: File.open("~/face.jpg"), filename: "face.jpg", content_type: "image/jpg")
|
||||
# person.avatar.attach(io: File.open("/path/to/face.jpg"), filename: "face.jpg", content_type: "image/jpg")
|
||||
# person.avatar.attach(avatar_blob) # ActiveStorage::Blob object
|
||||
def attach(attachable)
|
||||
if attached? && dependent == :purge_later
|
||||
|
|
Loading…
Reference in a new issue