
Untitled
By: a guest on
May 22nd, 2012 | syntax:
None | size: 0.68 KB | hits: 20 | expires: Never
can't access ActiveRecord mutators in a block
Prawn::Document.generate("hello.pdf") do
@model.field1
end
my_model = @model
Prawn::Document.generate("hello.pdf") do
my_model.field1
end
module Prawn
class Document
def self.generate(filename,options={},&block)
pdf = new(options,&block)
pdf.render_file(filename)
end
def initialize(options={},&block)
if block
block.arity < 1 ? instance_eval(&block) : block[self]
end
end
end
end
#lib/prawn/document.rb: Document#initialize
if block
block.arity < 1 ? instance_eval(&block) : block[self]
end
Prawn::Document.generate("hello.pdf") do |doc|
@my_model.field1
end