Ask A Question

Notifications

You’re not receiving notifications from this thread.

Multiple select for CSV Export?..

alexsunny asked in General

Hello,

My users can create a report record which is basically a scaffolded model "Report" with controller and views. The users can use this model to create records that a CSV method is using to query 2 other models: Order (parent) model and the corresponding Sale (child).

The Report model contains these columns:

t.datetime "start" (for createdat between (?) and (?))
t.datetime "end" (for createdat between (?) and (?))
t.string "brand" (brand = ?)
t.string "team" (team = ?)
Short excerpt of the CSV query looks like that:

Order.where("created_at between (?) and (?) and brand = ? and team = ?", self.start, self.end, self.brand, self.team).each do |order| order.sales.each do |sale|

This basically outputs each single Sale record in one line. So when 1 Order contains 5 sales, then 5 rows are printed into the CSV file.
That works perfectly with a single brand and a single team.

Now I want to do offer my users multiple select of brands and teams. E.g. when the brand is "Adidas" and "Nike" and the corresponding teams are "US" and "Europe" I want to put both outputs into one CSV instead having the user to create 2 reports.

I'm really struggling with that. What do I need to adjust so that multiple values are getting saved into one record, like brand = "Adidas, Nike" and team = "US, Europe" and then have this array parsed and get that into the CSV AR Query.

thanks
alexsunny

Reply
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,400+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.