I''m using hivelogic''s email enkoder and need help with a simple if/else statement. If there is a value for participant.student.email I would like to create the hyperlink for the email address, if not I would just like to list their name with no link. Can someone tell me how to do this? I can''t seem to get it to work or find any good information on using nil with IF/ELSE statements. [code]@name = "#{participant.student.last_name}, #{participant.student.first_name}" @email = participant.student.email if !@email.nil? enkode_mail(@email, @name) else @name end[/code] -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Looks OK to me, but I don''t know how enkode_mail works. Maybe you meant to assign the result of enkode_mail(..) to @email? @email = enkode_mail(@email, @name) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On Sun, Oct 15, 2006, John Saunders wrote:> > I''m using hivelogic''s email enkoder and need help with a simple if/else > statement. If there is a value for participant.student.email I would > like to create the hyperlink for the email address, if not I would just > like to list their name with no link. Can someone tell me how to do > this? I can''t seem to get it to work or find any good information on > using nil with IF/ELSE statements.Try using #blank? instead of #nil?. In all likelihood, what''s happening is you''re getting an empty string back from the database when it''s not present. Also, you might consider using unless instead of if !: unless @email.blank? enkode_mail @email, @name else @name end Ben --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Thanks for the help!! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2006-Oct-15 17:14 UTC
Re: Need help with a simple IF/ELSE statement?
Hi -- On Sun, 15 Oct 2006, Ben Bleything wrote:> > On Sun, Oct 15, 2006, John Saunders wrote: >> >> I''m using hivelogic''s email enkoder and need help with a simple if/else >> statement. If there is a value for participant.student.email I would >> like to create the hyperlink for the email address, if not I would just >> like to list their name with no link. Can someone tell me how to do >> this? I can''t seem to get it to work or find any good information on >> using nil with IF/ELSE statements. > > Try using #blank? instead of #nil?. In all likelihood, what''s happening > is you''re getting an empty string back from the database when it''s not > present. > > Also, you might consider using unless instead of if !: > > unless @email.blank? > enkode_mail @email, @name > else > @name > endOr, if like me you prefer to avoid the somewhat awkward unless/else sequence, you can switch the whole thing around: if @email.blank? @name etc. David -- David A. Black | dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB''s Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---