【发布时间】:2019-05-02 21:11:20
【问题描述】:
我正在开发一个 Rails 应用程序,并且我有一个 has_one_attached 个人资料图片用于在 S3 中进行主动存储,我想在我为我的用户播种时从 Faker 为他们的头像图像播种数据。 这是种子代码:
20.times do
Student.create(
first_name: Faker::Name.first_name,
last_name: Faker::Name.last_name,
phone_number: Faker::PhoneNumber.cell_phone,
school_id: School.first.id,
vehicle_make_model: Faker::Vehicle.make_and_model,
vehicle_year: Faker::Vehicle.year,
vehicle_color: Faker::Vehicle.color,
email_address: Faker::Internet.email,
password: "password",
email: Faker::Internet.email,
profile_picture: Faker::Avatar.image
).save
end
这是 User aka Student 的模型(设置正确并且在通过网站上传图像时有效):
class Student < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
belongs_to :school, optional: true
has_many :offers
has_many :comments
has_many :cars
has_one_attached :profile_picture
end
我之前已经播种了其余的数据,它工作正常,但是一旦我集成了 S3 并尝试使用这些数据播种,它就不再适合我了。
【问题讨论】:
标签: ruby-on-rails amazon-s3 seeding faker