puts "Work: #{@user.phone_work}" if !@user.phone_work.nil?
···
________________________________
From: yinwen Xuan <lists@ruby-forum.com>
To: ruby-talk@ruby-lang.org
Sent: Wednesday, November 20, 2013 3:54 PM
Subject: Re: ruby script if statement
Thanks Wayne
follow your instruction, I tried this:
<% "Work: #{@user.phone_work}" if @user.phone_work !=0 -%>
which is not work, the field will disappear not matter exist or not
any idea why?
Let me guess that you're actually talking about a Ruby *on Rails* application and don't realize that there is a separate mailing-list/forum for Rails questions.
If so, then you have ActiveSupport and the perfect method for this test:
@user.phone_work.blank? (or its opposite @user.phone_work.present?)
<% if @user.phone_work.present? -%>
Work: <%= @user.phone_work %>
<% end -%>
-Rob
···
On 2013-Nov-20, at 17:07 , yinwen Xuan <lists@ruby-forum.com> wrote:
HI thanks again Wayne!
I did tried
<% puts "Work: #{@user.phone_work}" if !@user.phone_work.nil? -%>
still the same, not showing at all no matter nil or not.