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.

This project is archived and is in readonly mode.

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

#4821

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

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

State: resolved
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Neeraj Singh
    Neeraj Singh

    Good catch.

    Please clone http://github.com/lifo/docrails, update the doc and push the changes.

    June 10th, 2010 @ 03:09 PM

  2. Evgeniy Dolzhenko
  3. DHH
    DHH
    • State changed from new to resolved

    June 10th, 2010 @ 04:59 PM

  4. Evgeniy Dolzhenko
  5. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 11th, 2010 @ 10:54 AM