【发布时间】:2013-05-24 13:48:07
【问题描述】:
基于 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
但它当然行不通。你知道怎么做吗?
【问题讨论】:
标签: arrays ruby-on-rails-3 prawn