I am trying to populate my database by parsing a JSON file and running a ruby script once that would create instances of my models and save them in my database.
file = File.read('players.json')
data_hash = JSON.parse(file)
data_hash_size = data_hash['Name'].size
data_hash.each_with_index do |i|
@student = student.new
@student.name = data_hash['Name'][i]
@student.college_year = data_hash['Cl.'][i]
Try placing your script file in Rail's
script directory. Once you place it there add this to the top of your file:
#! /usr/bin/env ruby require '../config/environment' .......script code.....