Nil Instead of Empty String

Hi All,

I am fairly new to rails. I am trying to cycle through an array of
activerecord objects and the view signals an error when I try to display
fields that are not specified.

I had expected the unspecified fields to return empty strings. What’s
the rationale in returning nil?

What’s the best way to deal with this? Currently I am calling the to_s
method for each field, but this doesn’t seem very elegant.

Thanks!

Will

If the fields are not defined in your database table, then rails cannot
create attributes for them in the ActiveRecord object.

Mick S. wrote:

If the fields are not defined in your database table, then rails cannot
create attributes for them in the ActiveRecord object.

They are defined. The schema is generated in migration for mysql5.
It’s just that when the field is empty it returns nil instead of an
empty string. When there are values in the field it works fine, but
when it returns nil it generates an error.

Can you pastie - http://pastie.caboo.se - us some code?

On Jan 19, 5:52 am, Willis 3000 [email protected]

They are defined. The schema is generated in migration for mysql5.
It’s just that when the field is empty it returns nil instead of an
empty string. When there are values in the field it works fine, but
when it returns nil it generates an error.

Let’s make it clear: is the field NULL in database, or is it indeed
empty?
These are not the same.

Regards,
Rimantas

http://rimantas.com/