less than 1 minute read

  1. Get API data > Save it as a JSON file
# lib/tasks/user.rake
namespace :user do
  desc "Enriching all users with Clearbit (async)"
  task :get_apidata => :environment do
	api_data =[{something}]
	File.write("data,json", JSON.generate(api_data))
  end
end

# How to run this code command line
# rails user:get_apidata
  1. Using the JSON file in the seed
data = JSON.parse(File.open(data.json).read)

Categories:

Updated: