Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String substitution within ruby array

I have the following code, within which I want to change certain values to csv friendly, e.g., 'nil' to ''. I need to know how to make these changes. Thank you.

  def daily_door_schedule
    @tickets = Ticket.where(active: true).
      pluck(
        :door_manufacturer,
        :job_number, 
        :door_style, 
        :door_allocation_date,
        :date_doors_received_in_aub, 
        :door_delivery_due_date,
        :notes
      )

    respond_to do |format|
      format.html
      format.csv { render text: @tickets.to_csv }
    end
  end
like image 691
listenlight Avatar asked May 02 '26 03:05

listenlight


1 Answers

This should do it:

@tickets = Ticket.where(active: true).
  pluck(
    :door_manufacturer,
    :job_number, 
    :door_style, 
    :door_allocation_date,
    :date_doors_received_in_aub, 
    :door_delivery_due_date,
    :notes
  ).map { |ticket| ticket.map(&:to_s) }
like image 58
Anthony Avatar answered May 03 '26 18:05

Anthony



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!