This project is archived and is in readonly mode.

#4821 ✓resolved
Evgeniy Dolzhenko

Validator defined with validates_each doesn't receive attr value on model creation

Reported by Evgeniy Dolzhenko | June 10th, 2010 @ 02:43 PM

Sorry for confusion, title of the ticket says the wrong thing, I removed non-relevant information from the ticket, it turned out to be just a minor docs mistake

here http://github.com/rails/rails/commit/a07d0f87863e01ef931c87bd35bd36...
there is example of using ActiveModel::Validations

class Person
  include ActiveModel::Validations

  attr_accessor :first_name, :last_name

  validates_each :first_name, :last_name do |record, attr, value|
    record.errors.add attr, 'starts with z.' if value.to_s[0] == ?z
  end
end

person = Person.new(:first_name => 'zoolander')
person.valid?          #=> false

which won't work and I believe the end should read like

person = Person.new
person.first_name = 'zoolander'
person.valid?          #=> false

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages