You could do this:
<td><%=task.assignee.username rescue nil %></td>
But is not that much better than unless.
HTH -
-Ezra
On Sep 23, 2005, at 11:28 AM, Brian Hogan wrote:
> I''ve run into this issue a lot and it''s really bothering
me.
>
> Models:
>
> Project has_many :tasks
>
> Task belongs_to :project
> belongs_to :assignee, :class_name => "User", :foreign_key
=>
> "assigned_to"
>
>
> View
>
> <td><%=task.assignee.username%></td>
>
>
> When the ''assigned_to'' field in the Tasks table is null
(nobody''s
> been assigned) then this line throws an error. What''s the
> preferred way of dealing with this short of surrounding this with <%
> unless task.assignee.nil? %>?
>
> It makes sense why it does this, but is there a way to have the
> view ignore nulls? Or do I just redefine what assignee does?
>
> Seems to me that this is a definite place for some improvement.
>
> Thanks in advance for your help!
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>