Skip to content

Instantly share code, notes, and snippets.

@mkllnk
Created March 23, 2020 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkllnk/326a806e6453dd668d86d60fe1a6bb79 to your computer and use it in GitHub Desktop.
Save mkllnk/326a806e6453dd668d86d60fe1a6bb79 to your computer and use it in GitHub Desktop.
Producer export
producers = Enterprise.is_primary_producer.joins(:address).where(spree_addresses: {state_id: 1061493592}).map { |e| {id: e.id, name: e.name, contact: e.contact_name, phone: e.phone, email: e.email_address, properties: e.producer_properties.map(&:value).join("|")} }
CSV.open("producers.csv", "wb") { |csv| csv << producers.first.keys; producers.each { |p| csv << p.values } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment