Forum: Ruby on Rails What am I doing wrong with this? :)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ef31136ad29b9ce06c9f718109a584cc?d=identicon&s=25 Pete (Guest)
on 2006-03-22 10:26
Hi,

I'm having trouble with a  piece of code based on an example someone
kindly posted  here:


errors.add('surname', "must be blank when the serial number is known")
if !surname.nil?|| !surname==""


Now, even if surname is empty, it still flags the error message. I
imagine I'm doing something rather obviously wrong but I'm not sure what
:)


Thanks in advance!
Ac1da5d66d51a1c3b843221032247b30?d=identicon&s=25 Eric Goodwin (Guest)
on 2006-03-22 10:39
(Received via mailing list)
Hi,
You should be able to shorten your statement down to this.

errors.add('surname', "must be blank when the serial number is known")
if !surname.blank?

Other than that, it should work. I'd have a look at what's getting
passed in for surname. Maybe change
your error message to:

errors.add('surname', "must be blank when the serial number is known.
You are passing in >>#{surname}<<") if !surname.blank?

That way you can make sure that nothing is getting passed in.

Cheers,
Eric Goodwin
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Richard Williams (Guest)
on 2006-03-22 15:03
(Received via mailing list)
Make sure the errors.add and the if are on the same line.
This topic is locked and can not be replied to.