Observer don't check if condition

3 views
Skip to first unread message

alex...@smallblind.de

unread,
May 15, 2008, 5:04:50 AM5/15/08
to Ruby on Rails: Talk
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

Frederick Cheung

unread,
May 15, 2008, 5:14:04 AM5/15/08
to rubyonra...@googlegroups.com

On 15 May 2008, at 10:04, alexBoSm...@googlemail.com 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

Murphyslaw

unread,
May 15, 2008, 5:20:20 AM5/15/08
to Ruby on Rails: Talk
Hi,

try using 'entry.field.blank?' instead of 'entry.field.nil?'.

Falk Köppe

On 15 Mai, 11:04, "alexBoSmallbl...@googlemail.com"

alex...@smallblind.de

unread,
May 15, 2008, 5:21:44 AM5/15/08
to Ruby on Rails: Talk


On May 15, 11:14 am, Frederick Cheung <frederick.che...@gmail.com>
wrote:
i tested both things but nothing works.

alex...@smallblind.de

unread,
May 15, 2008, 5:33:57 AM5/15/08
to Ruby on Rails: Talk


On 15 Mai, 11:21, "alexBoSmallbl...@googlemail.com"
DAMN it. it works, mistake by me !! Thanks for all your help
Reply all
Reply to author
Forward
0 new messages