4

I have a prawn table like the following:

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

I need to put a bottom border on the last row, but am not sure how to detect the last row inside the loop? Something like(the following if statement inside loop obviously doesn't work/ just example)...

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 

Any ideas are most welcomed.

I'm using Ruby - 2.1.2

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
polarcare
  • 575
  • 1
  • 6
  • 24

1 Answers1

8

You can try this:

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 
Sharvy Ahmed
  • 7,247
  • 1
  • 33
  • 46