Checking for nil in views


#1

Hello,

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

Manufacturer <%= @equipment.manufacturer.name unless @equipment.manufacturer.nil? %>

#2

Jim wrote:

Hello,

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

Manufacturer <%= @equipment.manufacturer.name unless @equipment.manufacturer.nil? %>

I don’ know about better, but

Manufacturer <%= @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


#3

Jim wrote:

Hello,

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

Manufacturer <%= @equipment.manufacturer.name unless @equipment.manufacturer.nil? %>

See this thread also:

http://www.ruby-forum.com/topic/53865#new