Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CSV.generate(options) do |csv|
- columns = %w(name, email_address)
- url = "@example.com"
- all.each do |location|
- csv << location.attributes.values_at(*columns) + [url]
- end
- end
- Joe, user1, @example.com
- Bob, user2, @example.com
- Joe, user1@example.com
- Bob, user2@example.com
- CSV.generate(options) do |csv|
- domain = "example.com"
- all.each do |location|
- csv << [location.name, "#{location.email_address}@#{domain}"]
- end
- end
- class Location << ActiveRecord::Base
- def full_email_address
- return "" if self.email_address.blank?
- domain = "example.com" # or save this as a constant in the class
- "#{self.email_address}@#{domain}"
- end
- end
- CSV.generate(options) do |csv|
- columns = %w{name full_email_address} # add other methods or attributes here
- all.each do |location|
- csv << columns.map{ |moa| location.public_send(moa) }
- end
- end
- CSV.generate(options) do |csv|
- columns = %w(name, email_address)
- url = "@example.com"
- all.each do |location|
- row = location.attributes.values_at(*columns)
- row[-1] = row[-1] + url
- csv << row
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement