Ruby prawn-table gem:如何选择表的最后一行?

时间:2015-03-09 21:01:49

标签: ruby-on-rails prawn ruby-2.1

我有一个如下的虾表:

table info_rows do
  row(0).font_style = :bold
  row(0).align = :center
  row(0).borders = [:top, :bottom, :left, :right]
  row(1..50).borders = [:left, :right]
  self.header = true
  self.row_colors = ['EEEEEE', 'FFFFFF']
  self.column_widths = col_sizes
end

我需要在最后一行放置一个底部边框,但我不确定如何检测循环内的最后一行?类似的东西(以下if语句内部循环显然不起作用/只是示例)...

table info_rows do
  row(0).font_style = :bold
  row(0).align = :center
  row(0).borders = [:top, :bottom, :left, :right]
  row(1..50).borders = [:left, :right]

  if row.last
    ?(?).borders = [:bottom, :left, :right]
  end

  self.header = true
  self.row_colors = ['EEEEEE', 'FFFFFF']
  self.column_widths = col_sizes
end 

欢迎任何想法。

我正在使用Ruby - 2.1.2

1 个答案:

答案 0 :(得分:6)

你可以试试这个:

table info_rows do
  row(0).font_style = :bold
  row(0).align = :center
  row(0).borders = [:top, :bottom, :left, :right]
  row(1..50).borders = [:left, :right]
  row(-1).borders = [:bottom, :left, :right]

  self.header = true
  self.row_colors = ['EEEEEE', 'FFFFFF']
  self.column_widths = col_sizes
end