# Princely Plugin: get nil.size error

**URL:** <https://www.ruby-forum.com/t/princely-plugin-get-nil-size-error/155763>\
**Category:** Rails\
**Created:** [December 16, 2008, 1:03pm UTC](https://www.ruby-forum.com/t/princely-plugin-get-nil-size-error/155763 "2008-12-16T13:03:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![brijesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f475e1/32.png) [@brijesh](https://www.ruby-forum.com/u/brijesh)\
**Post date:** [December 16, 2008, 1:03pm UTC](https://www.ruby-forum.com/t/princely-plugin-get-nil-size-error/155763/1 "2008-12-16T13:03:35Z")

</div>

Hi All,

I want to generate pdf with css. I am using princely plugin.

This is code which I written

def pdf  
prince = Prince.new()  
html\_string = render\_to\_string(:template =\>  
‘/users/paid\_invoice.pdf.erb’)  
send\_data(  
prince.pdf\_from\_string(html\_string),  
:filename =\> ‘some\_document.pdf’,  
:type =\> ‘application/pdf’  
)  
end

But I am getting error of nil.size

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.size

RAILS\_ROOT: /var/www/sortapp  
Application Trace | Framework Trace | Full Trace

/usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action\_controller/streaming.rb:123:in  
`send_data' app/controllers/users_controller.rb:135:in`pdf’

I also used make\_and\_send\_pdf function but got the same error.  
I thought I am getting error in render\_to\_string function.

Can anyone tell me how can I solve this issues?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![brijesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f475e1/32.png) [@brijesh](https://www.ruby-forum.com/u/brijesh)\
**Post date:** [August 9, 2009, 7:59am UTC](https://www.ruby-forum.com/t/princely-plugin-get-nil-size-error/155763/2 "2009-08-09T07:59:04Z")

</div>

Did you ever figure out this problem?

I have a working application and my code works on my laptop, but when I  
try it on our production server I come up with this error, but for the  
life of me I can’t figure out why it is being thrown on one machine and  
not the other.

NoMethodError: undefined method `size’ for nil:NilClass

[GEM\_ROOT]/gems/actionpack-2.1.0/lib/action\_controller/streaming.rb:123:in  
`send_data' [RAILS_ROOT]/vendor/plugins/princely/lib/pdf_helper.rb:45:in`make\_and\_send\_pdf’  
[RAILS\_ROOT]/vendor/plugins/princely/lib/pdf\_helper.rb:13:in `render' [RAILS_ROOT]/app/controllers/driver_payments_controller.rb:13:in`print’

Anyone got any ideas?

Thanks.

Brijesh S. wrote:

> Hi All,
> 
> I want to generate pdf with css. I am using princely plugin.
> 
> This is code which I written
> 
> def pdf  
> prince = Prince.new()  
> html\_string = render\_to\_string(:template =\>  
> ‘/users/paid\_invoice.pdf.erb’)  
> send\_data(  
> prince.pdf\_from\_string(html\_string),  
> :filename =\> ‘some\_document.pdf’,  
> :type =\> ‘application/pdf’  
> )  
> end
> 
> But I am getting error of nil.size
> 
> You have a nil object when you didn’t expect it!  
> You might have expected an instance of Array.  
> The error occurred while evaluating nil.size
> 
> RAILS\_ROOT: /var/www/sortapp  
> Application Trace | Framework Trace | Full Trace
> 
> /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action\_controller/streaming.rb:123:in  
> `send_data' app/controllers/users_controller.rb:135:in`pdf’
> 
> I also used make\_and\_send\_pdf function but got the same error.  
> I thought I am getting error in render\_to\_string function.
> 
> Can anyone tell me how can I solve this issues?
> 
> Thanks in advance

---

<div class="post-metadata">

**Author:** ![brijesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f475e1/32.png) [@brijesh](https://www.ruby-forum.com/u/brijesh)\
**Post date:** [August 10, 2009, 8:58am UTC](https://www.ruby-forum.com/t/princely-plugin-get-nil-size-error/155763/3 "2009-08-10T08:58:12Z")

</div>

Hi

Unfortunately I don’t remember it. I just remember that I applied a  
patch in one of the file of gem.  
Apply below patch in var/lib/gems/1.8/gems/htmldoc-0.2.0/lib/htmldoc.rb  
file.

@result[:output] = result  
result.split("\n").each do |line|

- line.strip! (patch)  
case line  
when /^BYTES: (\d+)/  
@result[:bytes] = $1.to\_i

Patch file is attached.

Let me know if this is worked or not.

Thanks  
Brijesh S.

Ash F. wrote:

> Did you ever figure out this problem?
> 
> I have a working application and my code works on my laptop, but when I  
> try it on our production server I come up with this error, but for the  
> life of me I can’t figure out why it is being thrown on one machine and  
> not the other.
> 
> NoMethodError: undefined method `size’ for nil:NilClass
> 
> [GEM\_ROOT]/gems/actionpack-2.1.0/lib/action\_controller/streaming.rb:123:in  
> `send_data' [RAILS_ROOT]/vendor/plugins/princely/lib/pdf_helper.rb:45:in`make\_and\_send\_pdf’  
> [RAILS\_ROOT]/vendor/plugins/princely/lib/pdf\_helper.rb:13:in `render' [RAILS_ROOT]/app/controllers/driver_payments_controller.rb:13:in`print’
> 
> Anyone got any ideas?
> 
> Thanks.
> 
> Brijesh S. wrote:
> 
> > Hi All,
> > 
> > I want to generate pdf with css. I am using princely plugin.
> > 
> > This is code which I written
> > 
> > def pdf  
> > prince = Prince.new()  
> > html\_string = render\_to\_string(:template =\>  
> > ‘/users/paid\_invoice.pdf.erb’)  
> > send\_data(  
> > prince.pdf\_from\_string(html\_string),  
> > :filename =\> ‘some\_document.pdf’,  
> > :type =\> ‘application/pdf’  
> > )  
> > end
> > 
> > But I am getting error of nil.size
> > 
> > You have a nil object when you didn’t expect it!  
> > You might have expected an instance of Array.  
> > The error occurred while evaluating nil.size
> > 
> > RAILS\_ROOT: /var/www/sortapp  
> > Application Trace | Framework Trace | Full Trace
> > 
> > /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.2/lib/action\_controller/streaming.rb:123:in  
> > `send_data' app/controllers/users_controller.rb:135:in`pdf’
> > 
> > I also used make\_and\_send\_pdf function but got the same error.  
> > I thought I am getting error in render\_to\_string function.
> > 
> > Can anyone tell me how can I solve this issues?
> > 
> > Thanks in advance

---

<div class="post-metadata">

**Author:** ![brijesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f475e1/32.png) [@brijesh](https://www.ruby-forum.com/u/brijesh)\
**Post date:** [August 11, 2009, 8:15am UTC](https://www.ruby-forum.com/t/princely-plugin-get-nil-size-error/155763/4 "2009-08-11T08:15:50Z")

</div>

This unfortunatly wasn’t the problem, but I did manage to figure out I  
only got it when running through mod\_rails. We just deployed the app to  
another server that was rebuilt from scratch and it is working now, so  
no idea what the actual cause was.

Thanks for the help.
