Organizationand Imagehave 1-to-1 relationship. Imagehas a column with a name filenamethat saves the file path. I have a file included in the channels app/assets/other/image.jpg. How to include the path to this file when sowing?
I tried in my seed file:
@organization = ...
@organization.image.create!(filename: File.open('app/assets/other/image.jpg'))
Both generate an error:
NoMethodError: undefined method `create!' for nil:NilClass
I checked with debuggerand can confirm that it is not @organization, which is zero.
How can I do this work and add the file path to the model Image?
Update . I tried the following:
@image = Image.create!(organization_id: @organization.id,
filename: 'app/assets/other/image.jpg')
And I also tried:
image = @organization.build_image(filename: 'app/assets/other/image.jpg')
image.save
When sowing, both attempts cause an error:
CarrierWave::FormNotMultipart: You tried to assign a String or a Pathname to an uploader, for security reasons, this is not allowed.
Marty source
share