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! -- Posted via http://www.ruby-forum.com/.
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 Pete wrote:> 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! > >
Make sure the errors.add and the if are on the same line. On Wednesday, March 22, 2006, at 10:26 AM, Pete wrote:>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! > >-- >Posted via http://www.ruby-forum.com/. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails-- Posted with http://DevLists.com. Sign up and save your time!