ruby数组中的字符串替换

时间:2015-09-08 18:04:09

标签: ruby-on-rails arrays ruby string

我有以下代码,其中我想将某些值更改为csv friendly,例如,' nil'到了'。我需要知道如何进行这些更改。谢谢。

  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

1 个答案:

答案 0 :(得分:3)

这应该这样做:

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