danielfone / as_csv Goto Github PK
View Code? Open in Web Editor NEWInstant CSV support for Rails
License: MIT License
Instant CSV support for Rails
License: MIT License
Hi!
First of all, thanks for this gem :)
I have an issue related to to_csv
method output. I can't find a way to exclude headers from the output. I've tried to pass { write_headers: false }
to csv_output
, but without success.
Is there any possibility at the moment to avoid headers in serialized output?
Thanks!
Hi,
First of all, thanks for your work on this gem!
I have noticed that since version 3, the gem is no longer loaded correctly for Rails 7 at least. I had to downgrade to 2.0.2 to have access to the as_csv
method on my records. Looks like the railtie is not functioning correctly?
Not sure what I'm doing wrong... I've installed the gem. ActiveModel::Serialization is included by models. Individual model to_csv
method works fine. But to_csv
on a relation doesn't work:
irb(main):014:0> Service < ActiveModel::Serialization
=> true
irb(main):015:0> Service.first.to_csv
=> "id,created_at,updated_at,type,name,gtfs_agency_id,logo,email,url,phone,start_or_end_area_id,trip_within_area_id,fare_structure,fare_details,archived\n1,2017-04-05 14:01:12 -0400,2017-04-20 13:34:28 -0400,Transit,Sample Transit Service,\"\",,,http://www.mbta.com,555-555-5555,,,,{:fare_table=>{}},false\n"
irb(main):016:0> Service.all.to_csv
undefined method `to_csv' for #<Service::ActiveRecord_Relation:0x007f9a4bbf5b20>
Did you mean? to_s
From the readme it sounds like I should be able to just install the gem, include Serialization on my model, and call to_csv on a relationship. Am I missing something?
Thanks!
FYI I'm using Ruby 2.4.0, Rails 5.0.2
I am attempting to use this gem but getting an UnknownFormat error.
Are there steps I missed in configuring my app to use the gem?
# Enrollment Controller
def roster
respond_to do |format|
format.csv { render csv: enrollments }
end
end
# Enrollment Model
def as_csv(options = {})
attributes
end
I also have a serializer exposing attributes for enrollments, just trying to brain storm on next steps in debugging this. Any thoughts?
I've added gem in my Gemfile
bundled new gems
Added method in my controller
def export_csv respond_to do |format| format.csv do format.csv { render csv: Widget.all } end end end
But when I open localhost:3000/export_csv.csv it returns this error
Missing template whatwebs/export_csv, application/export_csv with {:locale=>[:en], :formats=>[:csv], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.