Forum: Ruby on Rails Checking for nil in views

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7c3a0706ce454a5e7c405a63fdcd2c21?d=identicon&s=25 Jim (Guest)
on 2006-02-07 16:30
Hello,

Is there a better way to do the following in a view?

<td>Manufacturer <td><%= @equipment.manufacturer.name unless
@equipment.manufacturer.nil? %>
E555e7c34196967444a47a96395a23ab?d=identicon&s=25 Stefan Kaes (Guest)
on 2006-02-07 17:14
(Received via mailing list)
Jim wrote:
> Hello,
>
> Is there a better way to do the following in a view?
>
> <td>Manufacturer <td><%= @equipment.manufacturer.name unless
> @equipment.manufacturer.nil? %>
>
>
>
I don' know about better, but

<td>Manufacturer <td><%= @equipment.manufacturer.name rescue "unknown"
%>

would be shorter.

-- stefan

--
For rails performance tuning, see: http://railsexpress.de/blog
Subscription: http://railsexpress.de/blog/xml/rss20/feed.xml
7c3a0706ce454a5e7c405a63fdcd2c21?d=identicon&s=25 Jim (Guest)
on 2006-02-07 17:24
Jim wrote:
> Hello,
>
> Is there a better way to do the following in a view?
>
> <td>Manufacturer <td><%= @equipment.manufacturer.name unless
> @equipment.manufacturer.nil? %>

See this thread also:

http://www.ruby-forum.com/topic/53865#new
This topic is locked and can not be replied to.