Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Validate With Method not attaching error to optional field

#36

Given a model with the validation below, a produced error will be attached to the hash key :validate_username_unique instead of to :username.

validates_with_method :username, :validate_username_unique

def validate_username_unique

if new_record? || changed?(:username)
  if self.class.by_username( :key => self.username, :limit => 1).blank?
    return true
  else 
    return [false, "Username has already been taken"] 
  end 
else
  return true
end

end

# note: changed?(field) is a method added to the class, that is tested and works

Here is what the error inspection looks like:

<CouchRest::Validation::ValidationErrors:0x23a2e18 @errors={:validate_username_unique=>["Username has already been taken"]}>

Reported by ru_ghetto (at rubyghetto) · August 2nd, 2009 @ 01:54 PM

State: new
Milestone: none
Assigned to: nobody

Activity

No comments yet.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.