0

基于 Railscasts 的 Prawn 剧集,我想添加这样的行:

def line_items
  move_down 20
  table line_item_rows do
    row(0).font_style = :bold
    columns(1..3).align = :right
    self.row_colors = ["DDDDDD", "FFFFFF"]
    self.header = true
  end
end

def line_item_rows
  [["Product", "Qty", "Unit Price", "Full Price"]] +
  @order.line_items.map do |item|
    [item.name, item.quantity, price(item.unit_price), price(item.full_price)]
  end
end

我想在“@order.line_items”行之后动态添加行,但我不知道该怎么做,然后我尝试了:

def line_item_rows
  [["Product", "Qty", "Unit Price", "Full Price"]] +
  @order.line_items.map do |item|
    [item.name, item.quantity, price(item.unit_price), price(item.full_price)]
  end

  @order.other_line_items.map do |item|
    [item.name, item.quantity, price(item.unit_price), price(item.full_price)]
  end
end

但当然它不起作用。你知道怎么做吗 ?

4

1 回答 1

0

解决方案很简单:

data = data + 
  @order.other_line_items.map do |item|
    [item.name, item.quantity, price(item.unit_price), price(item.full_price)]
  end
于 2013-05-24T15:47:19.987 回答