Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

how to write CSV file in rails

require 'csv'
file = "my_file.csv"
CSV.open( file, 'w' ) do |writer|
  @coun.each do |c|
    writer << [c.name, c.country_code, c.user_id, c.subscriber_id]
  end
end
Comment

generate csv file rails

def csv_cars
  headers = ['column one', 'column two', 'column three']

  csv_data = CSV.generate(headers: true) do |csv|
    csv << headers
    csv << ["A", "B", "C"]
  end

  send_data csv_data, filename: "data-#{Date.today.to_s}.csv", disposition: :attachment
end
Comment

PREVIOUS NEXT
Code Example
Ruby :: new date ruby 
Ruby :: ruby boolean variable 
Ruby :: ruby test is number 
Ruby :: ruby pop array 
Ruby :: how to create 2 dimensional array in ruby 
Ruby :: ruby sort array numerically 
Ruby :: ruby map array 
Ruby :: ruby is character 
Ruby :: ruby class 
Ruby :: rails setup test db 
Ruby :: rails reference a column with another name 
Ruby :: rails transactions 
Ruby :: pg_ctl: no database directory specified and environment variable PGDATA unset 
Ruby :: ActionController::InvalidAuthenticityToken rails when submitting form 
Ruby :: grails 3 cron jobs 
Ruby :: rails retrieve database.yml 
Ruby :: rails controller generator 
Ruby :: ruby rails migrate check status 
Ruby :: add index in rails 
Ruby :: ruby merge arrays unique 
Ruby :: ruby rspec change matcher 
Ruby :: rails faker address 
Ruby :: rails multiple rescue 
Ruby :: irb loaderror 
Ruby :: capybara click with offset 
Ruby :: In Jekyll - get the parent url path of a collection 
R :: linetype ggplot in r 
R :: How to Export a DataFrame to Excel File in R 
R :: merge multiple objects in r 
R :: how to multiply two columns in r 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =