# Observer don't check if condition

**URL:** <https://www.ruby-forum.com/t/observer-dont-check-if-condition/137689>\
**Category:** Rails\
**Created:** [May 15, 2008, 11:05am UTC](https://www.ruby-forum.com/t/observer-dont-check-if-condition/137689 "2008-05-15T11:05:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 15, 2008, 11:05am UTC](https://www.ruby-forum.com/t/observer-dont-check-if-condition/137689/1 "2008-05-15T11:05:38Z")

</div>

Hi,  
i have a problem with the mail deliver after a entry is save.  
I want to check if one field is filled. In every Option (Controller  
action, model, observer) i wrote a

if !entry.field.nil?  
Mail.deliver\_entry(entry)  
end

But i get this mail also if the entry field is nil.

I also wrote a EntryObserver which implements the following method

def after\_save(entry)  
Mail.deliver\_entry(entry) if !entry.field.nil?  
end

can anybody tell me, why this doesn’t work for me?

thanks alex

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 15, 2008, 11:15am UTC](https://www.ruby-forum.com/t/observer-dont-check-if-condition/137689/2 "2008-05-15T11:15:06Z")

</div>

On 15 May 2008, at 10:04, removed\_email\_address@domain.invalid wrote:

> But i get this mail also if the entry field is nil.
> 
> I also wrote a EntryObserver which implements the following method
> 
> def after\_save(entry)  
> Mail.deliver\_entry(entry) if !entry.field.nil?  
> end
> 
> can anybody tell me, why this doesn’t work for me?

I suspect what is happening is that entry.field is the empty string  
(which is of course not nil). .blank? checks for both nil and the  
empty string

Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 15, 2008, 11:21am UTC](https://www.ruby-forum.com/t/observer-dont-check-if-condition/137689/3 "2008-05-15T11:21:05Z")

</div>

Hi,

try using ‘entry.field.blank?’ instead of ‘entry.field.nil?’.

Falk Köppe

On 15 Mai, 11:04, “removed\_email\_address@domain.invalid”

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 15, 2008, 11:34am UTC](https://www.ruby-forum.com/t/observer-dont-check-if-condition/137689/4 "2008-05-15T11:34:45Z")

</div>

On 15 Mai, 11:21, “removed\_email\_address@domain.invalid”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Fred
> 
> i tested both things but nothing works.

DAMN it. it works, mistake by me !! Thanks for all your help

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 15, 2008, 11:22am UTC](https://www.ruby-forum.com/t/observer-dont-check-if-condition/137689/5 "2008-05-15T11:22:52Z")

</div>

On May 15, 11:14 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > end
> 
> > can anybody tell me, why this doesn’t work for me?
> 
> I suspect what is happening is that entry.field is the empty string  
> (which is of course not nil). .blank? checks for both nil and the  
> empty string
> 
> Fred

i tested both things but nothing works.
