我正在使用 Prawn 生成 PDF 文档,但在尝试为项目生成表格时出现上述错误。关于如何去做的任何想法?
应用程序/模型/storage_request.rb
class StorageRequest < ActiveRecord::Base
has_many :packages
accepts_nested_attributes_for :packages, :allow_destroy => true
attr_accessible :user_id, :state, :packages_attributes
end
应用程序/模型/package.rb
class Package < ActiveRecord::Base
belongs_to :storage_request
has_many :items
accepts_nested_attributes_for :items, allow_destroy: true
attr_accessible :user_id, :state, :items_attributes
end
应用程序/模型/item.rb
class Item < ActiveRecord::Base
belongs_to :package
attr_accessible :name, :user_id
end
app/pdfs/storage_request_pdf.rb
class StorageRequestPdf < Prawn::Document
def initialize(storage_request, view)
super(top_margin: 50)
@storage_request = storage_request
@view = view
list_items
end
def list_items
move_down 20
text "Summary", size: 30, style: :bold, align: :center
table item_rows do
row(0).font_style = :bold
self.row_colors = ["DDDDDD", "FFFFFF"]
self.header = true
end
end
def item_rows
@storage_request.packages.map do |package|
package.items.map do |item|
([["ID", "Item Name"]] +
[item.id, item.name])
end
end
end
end