我想用一些包含活动存储附件的实例播种我的数据库,但我不知道我怎么做 . 我尝试了一些方法,但没有成功 .
有我的种子 .
User.create(email: "test@ok.com", password: "okokok") if User.count.zero?
50.times do |i|
temp = Template.create(
title: Faker::Name.name,
description: Faker::Lorem.paragraph(2),
user: User.first,
github_link: Faker::SiliconValley.url,
category: rand(0...4)
)
puts Template.first.photo
temp.photo.attach(Template.first.photo)
end
谢谢你的帮助
2 回答
几天后它也出现在文档指南中:
http://edgeguides.rubyonrails.org/active_storage_overview.html#attaching-file-io-objects
好的,我找到了一个解决方案,我发布给同样情况下的人:
如果你有更简单的解决方案分享它;)