Ruby on Rails - Scaffolding and Seeding Example

Create the model
rails g scaffold MasterGrant community_goal:string funding_source:string fund_name_type:string area_of_focus:string oversight_department:string oversight_division:string entity_name:string program_project_name:string fy2019_20:string fy2020_21:string fy2021_22:string total_funding_investment:string dashboard_status:string tag:string notes:string 

Create directory /lib/seeds/ and upload CSV file that will be used for seeding.  In this case the filename is master_grants.csv

Edit seeds.rb and add the following

require 'csv'
csv_text = File.read(Rails.root.join('lib', 'seeds', 'master_grants.csv'))
csv = CSV.parse(csv_text, :headers => true, :encoding => 'ISO-8859-1')
csv.each do |row|
t = MasterGrant.new
t.community_goal = row['Community Goal']
t.funding_source = row['Funding Source']
t.fund_name_type = row['Fund Name Type']
t.area_of_focus = row['Area Of Focus']
t.oversight_department = row['Oversight Department']
t.oversight_division = row['Oversight Division']
t.entity_name = row['Entity Name']
t.program_project_name = row['Program Project Name']
t.fy2019_20 = row['Fy 2019-20']
t.fy2020_21 = row['Fy 2020-21']
t.fy2021_22 = row['Fy 2021-22']
t.total_funding_investment = row['Total Funding Investment']
t.dashboard_status = row['Dashboard Status']
t.tag = row['Tag']
t.notes = row['Notes']
t.save
puts "#{t.program_project_name} saved"
end
Run command to seed the database
rails db:seed
This should display a stream of 'Program Projects Names' in the terminal and insert all the rows into the database.