NoMethodError in Payslips#to_pdf

22 views
Skip to first unread message

Chee Chong Hwa

unread,
Feb 4, 2017, 6:02:09 AM2/4/17
to Prawn
Hi All

Followed the Railcast # 158 on PDF with Prawn

Click the to_pdf link and get the following error message

NoMethodError in Payslips#to_pdf

Showing C:/RubymineProjects/pms4mysql/app/views/payslips/to_pdf.pdf.prawn where line #5 raised:

undefined method `eno' for nil:NilClass
Extracted source (around line #5):
3
4
5
6
7
8
              
pdf.move_down(30)
payslips=[payslips.eno, payslips.ename, payslips.dept, payslips.netpay]
#items = @order.cart.line_items.map do |item|
# [

to_pdf.pdf.prawn (my table is paylips with fields eno,ename,netpay)
================
#pdf.text "Order ##{@order.id}", :size => 30, :style => :bold
pdf.text "Payslip ##{@payslip.eno}", :size => 30, :style => :bold
pdf.move_down(30)

payslips=[payslips.eno, payslips.ename, payslips.dept, payslips.netpay]
#items = @order.cart.line_items.map do |item|
# [
# item.product.name,
# item.quantity,
# number_to_currency(item.unit_price),
# number_to_currency(item.full_price)
# ]
#end

pdf.table items, :border_style => :grid,
:row_colors => ["FFFFFF","DDDDDD"],
:h
eaders => ["Employee #", "Name", "Dept", "Net Pay"],
:align => { 0 => :left, 1 => :right, 2 => :right, 3 => :right }

pdf.move_down(10)


Alexander Mankuta

unread,
Feb 4, 2017, 6:05:26 AM2/4/17
to Prawn
Hello,

It looks like your model doesn't have eno field.

This is unrelated to Prawn in any way, though.

--
Regards,
Alex

Chee Chong Hwa

unread,
Feb 4, 2017, 6:20:03 AM2/4/17
to Prawn
Hi Alex

Just checked, there is a eno field in the model which is why I am puzzled on the erro message.
What else can I check for ?

TIA

Alexander Mankuta

unread,
Feb 4, 2017, 7:23:24 AM2/4/17
to prawn...@googlegroups.com

On closer inspection payslips appears to be nil. Check if you've assigned it properly (typos?).



--
Regards,
Alexander
-- You received this message because you are subscribed to the Google Groups "Prawn" group. To unsubscribe from this group and stop receiving emails from it, send an email to prawn-ruby+...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
signature.asc

Chee Chong Hwa

unread,
Feb 4, 2017, 9:46:01 AM2/4/17
to Prawn, al...@pointless.one
Hi Alexander

I replace # payslips=[payslips.eno, payslips.ename, payslips.dept, payslips.netpay]
with pdf.text="we made it"

Still got an error message

NoMethodError in Payslips#to_pdf

Showing C:/RubymineProjects/pms4mysql/app/views/payslips/to_pdf.pdf.prawn where line #6 raised:

undefined method `text=' for #<Prawn::Document:0xbc1ec70>
Extracted source (around line #6):
4
5
6
7
8
9
              
# payslips=[payslips.eno, payslips.ename, payslips.dept, payslips.netpay]
pdf.text="we made it"
#items = @order.cart.line_items.map do |item|
# [
Reply all
Reply to author
Forward
0 new messages