Reputation: 3
path = Rails.root.join('app', 'assets','cards.json')
as the path for the file to read.
I have a Json file and I want to use the data to create Ruby objects in my database.
I tried to use this in my seed.rb but it won't open the json. Is there a better approach to what I am trying to do?
#seeds.rb
require 'json'
cards = JSON.parse(File.read('cards.json'))
cards["cards"].each do |card|
Card.create(card)
end
running rails db:seed
Errno::ENOENT: No such file or directory @ rb_sysopen - cards.json
Upvotes: 0
Views: 543