Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > trying to fo this right

Reply
Thread Tools

trying to fo this right

 
 
Helder Oliveira
Guest
Posts: n/a
 
      01-09-2007
if
i.timesheets.find(:first,:select=>'inserida',rde r=>'inseridaDESC').inserida.to_s(:db).nil?
miss = 'nemhuma inserida'
else
miss = _
end

i know the _ isnt right, but im trying not to make the query 2 times,
how can i make that if not doing the query two times ?

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Jan Svitok
Guest
Posts: n/a
 
      01-09-2007
On 1/9/07, Helder Oliveira <(E-Mail Removed)> wrote:
> i know the _ isnt right, but im trying not to make the query 2 times,
> how can i make that if not doing the query two times ?


either

ret = i.timesheets.find(:first,:select=>'inserida',rde r=>'inseridaDESC').inserida.to_s(:db)
if ret.nil?
miss = 'nemhuma inserida'
else
miss = ret
end

or (ugly)

if (ret = i.timesheets.find(:first,:select=>'inserida',rde r=>'inseridaDESC').inserida.to_s(:db)).nil?
miss = 'nemhuma inserida'
else
miss = ret
end

NB you can rewrite the first one as:

ret = i.timesheets.find(:first,:select=>'inserida',rde r=>'inseridaDESC').inserida.to_s(:db)
miss = ret.nil? ? 'nemhuma inserida' : ret

or if the result is some object (not false) then you can do

ret = i.timesheets.find(:first,:select=>'inserida',rde r=>'inseridaDESC').inserida.to_s(:db)
miss = ret || 'nemhuma inserida'

or even
miss = i.timesheets.find(:first,:select=>'inserida',rde r=>'inseridaDESC').inserida.to_s(:db)
|| 'nemhuma inserida'

(if the result is not nil, then only the first term will be evaluated,
otherwise also the second will be).

----
Another issue: I suspect you'll have problem when find() returns nil
(i.e. nothing's found) and you'll be calling nil.inserida.to_s(:db). I
suppose you'd check that nil as well.

i.timesheets.find(:first,:select=>'inserida',rde r=>'inseridaDESC').*possible
nil HERE*inserida.to_s(:db)

 
Reply With Quote
 
 
 
 
Helder Oliveira
Guest
Posts: n/a
 
      01-09-2007
thanks man

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Menu Items is not right aligned with Right to Left documen =?Utf-8?B?QmlzaG95?= ASP .Net 0 12-28-2006 11:39 AM
Right-Click With Mouse and Toolba Buttonsr Don't Work Right Bigfoot It Is Computer Support 0 10-30-2006 06:08 PM
Tool to enable Right click on pages where Right click is disabled tsteinke@gmail.com Computer Support 4 08-28-2005 11:53 PM
Tool to right click image in windows explorer and rotate image right or left 90 degrees siliconpi Digital Photography 2 11-29-2004 12:56 PM
pass the right form input to the right control Tom ASP .Net 0 12-11-2003 03:07 AM



Advertisments