listenlight
listenlight

Reputation: 662

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

Upvotes: 3

Views: 120

Answers (1)

Anthony
Anthony

Reputation: 15997

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) }

Upvotes: 3

Related Questions