How about doing this as a concern instead?
# models/concerns/generate_csv.rb module GenerateCSV extend ActiveSupport::Concern class_methods do def generate_csv CSV.generate(headers: true) do |csv| csv << self.attribute_names all.each do |record| csv << record.attributes.values end end end end end
Then
# models/user.rb class User include GenerateCSV end
or
# models/whatever.rb class Whatever include GenerateCSV end
Great for DRY approach, thanks for this :)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
How about doing this as a concern instead?
Then
or
Great for DRY approach, thanks for this :)