问题
I've run into a really strange issue with my rails/prawn code.
I'm generating a table and trying to change the font style of the first row with the following code:
pdf.table(data) do
rows.first.style(:font_style => :bold)
end
The table is generated, but nothing inside the block is executed. I've tried putting a debugger statement in the block, but it doesn't even hit that. As per suggestions found by Googling, I've tried adding a block argument, eg:
pdf.table(data) do |t|
t.rows.first.style(:font_style => :bold)
end
along with several other variations, but to no avail. I've tried various configurations by changing config/environments.rb, but that didn't work either. Specifically, my questions is, why isn't the code inside the block executing?
I'd greatly appreciate any suggestions anyone might have.
回答1:
We had similar issues with tables in prawn. I think the syntax had changed from a lot of the guides around out there, but I can't really remember - it was a while back! This is how we went about styling a row in the end:
pdf.table(data) do
style row(0), :style => :bold
end
回答2:
both
style(row(0)) {|x| x.font_style = :bold}
and
style row(0), :font_style => :bold
works for me. Your
style => :bold
does not work. Btw: prawn (0.12.0) here.
来源:https://stackoverflow.com/questions/4430013/prawn-tables-block-is-not-executing