By the way, Ezra, thank you for that tip. That''s probably the neatest
thing I''ve learned from this list.
-----Original Message-----
From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On
Behalf Of Ezra
Zygmuntowicz
Sent: Thursday, October 13, 2005 1:44 PM
To: twa-pCGr9Sw2R8Y@public.gmane.org;
rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: Re: [Rails] Issue with Objects Not Existing
You could do:
<%= @message rescue nil %>
And it will output the message if there is one. If the message is nil
nothing will happen, it won''t throw and error and it will continue on
with you script.
Cheers-
-Ezra
On Oct 13, 2005, at 5:06 AM, Tom Ayerst wrote:
> you could use:
>
> <%=@message unless not @message %>
>
> Which will print an empty string if @message is an empty string. If
> you don''t want to output anything if @message is empty then:
>
> <%if @message && not @message.empty? then%>
> <%=@message%>
> <%end%>
>
> but I''m fairly new at this and there may be a more *Rubyish* way
>
> Tom
>
> Joseph Lyons wrote:
>
>
>> In my standard Layout, I have a section which will output an error
>> if one
>> exists.
>>
>> Here is the code:
>>
>>
>> <%unless @message.empty? then%>
>> <%=@message%>
>> <%end%>
>> The problem I''m having sometimes is that the object @message
may
>> not have
>> been created in a method that being displayed and I get the error
>> undefined method `empty?'' for nil:NilClass
>> I''m wondering how to elegantly handle this, basically display
an
>> error only
>> if the object exists and it''s not empty. I''m sure
there is an
>> obvious
>> solution (other than creating a @message object in every method,
>> and I don''t
>> want to use flash)
>> Thanks,
>>
>> Joe
>>
>>
>>
>> ---------------------------------------------------------------------
>> ---
>>
>> _______________________________________________
>> Rails mailing list
>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>> http://lists.rubyonrails.org/mailman/listinfo/rails
>>
>> ---------------------------------------------------------------------
>> ---
>>
>> No virus found in this incoming message.
>> Checked by AVG Anti-Virus.
>> Version: 7.0.344 / Virus Database: 267.11.14/131 - Release Date:
>> 12/10/2005
>>
>>
>>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
-Ezra Zygmuntowicz
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails