Answers for "ruby require csv"

1

ruby create CSV

CSV.open("file.csv", "a+") do |csv|
  csv << ["cow", "3","2500"]
end
Posted by: Guest on March-13-2020
0

ruby on rails csv import

// Model
require 'csv'

def self.import(file)
    CSV.foreach(file.path, headers: true) do |row|
      to_hash = row.to_hash

      // Deal with to_hash header and data. Example Create
      user = create(
                          name: to_hash['name'], 
        				  email: to_hash['email'], 
        				  lastname: to_hash['lastname']
                        )
    end
end


// Controller
def import
   Model.import(params[:file])
end

// View
= form_tag route_path, multipart: true, remote: true do
	= file_field_tag :file,
	= button_tag 'Import'
Posted by: Guest on August-14-2020
0

generate csv ruby

require 'csv'
csv_string = CSV.generate do |csv|
  csv << ["row", "of", "CSV", "data"]
  csv << ["another", "row"]
  # ...
end
Posted by: Guest on February-03-2021

Browse Popular Code Answers by Language