Checking Join data for nil

J

Justin Kay

So I have a join 1:0..1. If there is nothing in the child side I get an
error when I say property.pdf.name that I can't access nil.name. But I
can't seem to figure out how to check if pdf is nil or not before I call
the .name function. If I test for property.pdf == nil it always comes
back as nil, which it isn't.

Any ideas?
 
R

Ryan Leavengood

So I have a join 1:0..1. If there is nothing in the child side I get an
error when I say property.pdf.name that I can't access nil.name. But I
can't seem to figure out how to check if pdf is nil or not before I call
the .name function. If I test for property.pdf =3D=3D nil it always come= s
back as nil, which it isn't.

Any ideas?

I'm not exactly sure what you are doing, but in general to check for
nil you can just use "if" like so (nil is false):

if property.pdf
puts property.pdf.name
end

Or if you want to be explicit:

unless property.pdf.nil?
puts property.pdf.name
end

If property.pdf is always nil, then you have some other bug in your code.

Ryan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top