Ruby on rails 对虾如何使用对虾填写表单字段?

Ruby on rails 对虾如何使用对虾填写表单字段?,ruby-on-rails,templates,prawn,Ruby On Rails,Templates,Prawn,我正在rails3.0应用程序中使用prawnggem0.12.0 我的文档显示为: class TemplatePdf < Prawn::Document def initialize filename= "#{Prawn::BASEDIR}/data/pdfs/RMA_Formular.pdf" super(:template => filename) text_box "2005-xxxx1055", :at=>[40,472]

我正在
rails3.0
应用程序中使用
prawnggem0.12.0

我的文档显示为:

class TemplatePdf < Prawn::Document
def initialize

filename= "#{Prawn::BASEDIR}/data/pdfs/RMA_Formular.pdf"
        super(:template => filename)
        text_box "2005-xxxx1055", :at=>[40,472]
        text_box "#{current_user.email}", :at =>[280, 472]
        text_box ...
...
end

这将按预期填充pdf的表单字段,并将我从每个模板设计的硬编码绝对位置中解救出来。

我没有尝试过这个,但我从示例中注意到:
:at=>[x,y]
是一个强制选项,用于将元素准确地定位在
(x,y)处
文档的位置

如果不想精确定位在
(x,y)
位置,可以使用
text
方法,如下所示

text "Some string"
move_down 20
text "Some other string"

另一种选择是,您可以在yml文件中为每个字段保留这些位置值,并在中重用,而不是在代码中硬编码。

我想您理解错了。模板可能会更改,因此可能会更改电子邮件字段的位置,但仍然会有电子邮件字段。如果我使用:at=>[x,y]编码,我必须重新编程模板每次更改的位置。是否有方法读取现有PDF并以编程方式查找现有字段的位置。
text "Some string"
move_down 20
text "Some other string"