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.
Jim (Guest)
on 2006-02-07 17:30
Hello,

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

<td>Manufacturer <td><%= @equipment.manufacturer.name unless
@equipment.manufacturer.nil? %>
Stefan K. (Guest)
on 2006-02-07 18: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
Jim (Guest)
on 2006-02-07 18: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.