Skip to content

Instantly share code, notes, and snippets.

some.code(before)
eval(Pathname(__FILE__).dirname.join('_bar.pdf.prawn').read)
some.code(after)
def show
# ...
send_file_headers! \
:disposition => 'attachment', :filename => "foo-#{@foo.to_param}.pdf",
:type => Mime::PDF, :length => false
end
pdf.text "Hello World!"
bounding_box [100, 600], :width => 200 do
text "The rain in spain falls mainly on the plains " * 5
stroke do
line bounds.top_left, bounds.top_right
line bounds.bottom_left, bounds.bottom_right
end
end
text "Hello World!"
pdf.bounding_box [100, 600], :width => 200 do
pdf.text "The rain in spain falls mainly on the plains " * 5
pdf.stroke do
pdf.line pdf.bounds.top_left, pdf.bounds.top_right
pdf.line pdf.bounds.bottom_left, pdf.bounds.bottom_right
end
end
article = Article.new.save(false) # would be ideal, but `article' equals true here
article = Article.new
article.save(false) # => true
comment = article.comments.build
comment.save(false) # => true
# ...use these records here...
article = insert! Article
comment = insert! Comment, :article => article
# ...use these records here...
# This is an augmented version of the original `insert!'. In addition to the
# original functionality, it allows for specifying:
#
# - :trigger_validation: whether to trigger validation after the record has
# been instantiated. Default: false.
#
# - :inhibit_callbacks: whether to inhibit callbacks supposed to be triggered
# after validation. Default: true.
#
# Also, now, any attribute can be assigned, regardless of their being declared
article = Article.new { |a| a.save(false) }
comment = article.comments.build { |c| c.save(false) }