Save 36% for Black Friday! Learn more

All threads / Multiple select for CSV Export?..
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

Join the discussion

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

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

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

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.