I have an attribute :x in a form
validates_each manages to be able to get to the value of :x in the form.
(Source for validates_each from http://api.rubyonrails.org/)
# File vendor/rails/activerecord/lib/active_record/validations.rb,
line 390
390: def validates_each(*attrs)
391: options = attrs.extract_options!.symbolize_keys
392: attrs = attrs.flatten
393:
394: # Declare the validation.
395: send(validation_method(options[:on] || :save), options) do
|record|
396: attrs.each do |attr|
397: value = record.send(attr)
398: next if (value.nil? && options[:allow_nil]) ||
(value.blank? && options[:allow_blank])
399: yield record, attr, value
400: end
401: end
402: end
I think I want to do
record.send(:x)
but I am unable to follow the logic to understand where record comes
from.
Ralph S. wrote:
I have an attribute :x in a form
validates_each manages to be able to get to the value of :x in the form.
[…]
I think I want to do
record.send(:x)
Why do you think you want to do that? What are you trying to achieve?
How are we supposed to help with so little information?
but I am unable to follow the logic to understand where record comes
from.
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
Marnen Laibow-Koser wrote:
Ralph S. wrote:
I have an attribute :x in a form
validates_each manages to be able to get to the value of :x in the form.
[…]
I think I want to do
record.send(:x)
Why do you think you want to do that? What are you trying to achieve?
How are we supposed to help with so little information?
but I am unable to follow the logic to understand where record comes
from.
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
I am trying to understand the magic of validates_each. I have traced
the logic to the point where it does a
record.send(:x)
and I am trying to understand where the entity “record” comes from so
that I can capture the value in the form associate with the symbol :x.
Ralph S. wrote:
[…]
I am trying to understand the magic of validates_each. I have traced
the logic to the point where it does a
record.send(:x)
and I am trying to understand where the entity “record” comes from so
that I can capture the value in the form associate with the symbol :x.
As an academic exercise, this may be valuable. For practical purposes,
you probably don’t need to do this – just look in the params hash.
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]