error data must be a two dimensional array of cellable objects

602 views
Skip to first unread message

azren

unread,
Jun 10, 2013, 6:34:51 AM6/10/13
to Prawn
Hi All,

I'm using prawn to generate pdf document but getting the above error
when trying to generate tables for items in pdf. Any idea on how to go
about this.

Thank you.

models:

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 StorageRequest < 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 StorageRequest < 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

Controller:

Class StorageRequestsController < ApplicationController

def show
@storage_request = StorageRequest.find(params[:id])
respond_to do |format|
format.html
format.pdf do
pdf = StorageRequestPdf.new(@storage_request, view_context)
send_data pdf.render, filename:
"storage_request_#{@storage_request.user.full_name}.pdf",
type: "application/pdf",
disposition: "inline"
end
end
end
end

http://stackoverflow.com/questions/17020951/prawn-error-data-must-be-a-two-dimensional-array-of-cellable-objects

Brad Ediger

unread,
Jun 10, 2013, 11:26:19 AM6/10/13
to prawn-ruby
On Mon, Jun 10, 2013 at 5:34 AM, azren <w.m....@gmail.com> wrote:
> I'm using prawn to generate pdf document but getting the above error
> when trying to generate tables for items in pdf. Any idea on how to go
> about this.


> 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

Take a look at the result you're getting from this method. I suspect
it is not quite what you were expecting; each `map` is going to create
another nested level of arrays.
Reply all
Reply to author
Forward
0 new messages