2017-10-16 69 views
0
artistOne.arts.create!(
    genre:'Interior', 
    description:'Interior paintings/drawings typically exclude or de-emphasize the presence of people or pets.', 
    price:200, 
    length:30, 
    width:40, 
    medium:'Oil', 
    artist: artistOne, 
    user: user, 
    :image_file_name => File.open(File.join(Rails.root, 'app/assets/images/artistOne.jpg')) 
) 

我需要播種數據圖像,因爲我的網站使用paperclip上傳圖片的方法幫助一個網站。我想知道如果我在播種圖像文件方面處於寫作軌道?播種數據軌與使用回形針上傳圖片

回答

-1

你必須把你的文件在公共文件夾,讀它,並將其轉換爲base64,內容:

image_file_name: 'data:image/jpeg;base64,' + Base64.encode64(File.open('public/path_to_file.jpg', 'rb').read) 

不要忘記

require 'base64' 
+1

不知道這是否與他的問題有關。 – Cyzanfar

0

你是在正確的軌道上。只需在image_file_name字段添加您的模型附件:

class Art < ActiveRecord::Base 
    has_attached_file : image_file_name 
end 

artistOne.arts.create!(
    genre:'Interior', 
    description:'Interior paintings/drawings typically exclude or de-emphasize the presence of people or pets.', 
    price:200, 
    length:30, 
    width:40, 
    medium:'Oil', 
    artist: artistOne, 
    user: user, 
    image_file_name: File.open('/path/to/image.jpg', 'rb') 
) 
相關問題