Re: Re: display optional db data

Hassan Schroeder
2010-04-15T18:59:45Z

On Thu, Apr 15, 2010 at 11:36 AM, dan
<mr.dan.marks-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> if thing.foo is a date, price, url or something else that requires
> formatting, it requires more than =thing.foo
> and since you cant format nil, a test needs to be performed before
> trying to format said data
> my views are getting littered with these tests and formats, sometimes
> there nested:

Some possible approaches:

1)  make the default in the database some value other than null.

2) <%= @thing.foo.format rescue nil %>

3) <%= @thing.foo.nil? ? " N/A " : @thing.foo.format %>

I''m sure someone will suggest others, but HTH  :-)

--
Hassan Schroeder ------------------------
hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
twitter: @hassan