Hey all,

I look at the rails documentation validation helpers:

http://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html

It has this example:

class Person < ActiveRecord::Base
  validates_inclusion_of :states, :in => lambda{ |person|
STATES[person.country] }
end

So basically when you update a record, that object instance is passed
into the lambda and validation occurs.

I try to emulate same thing:

class Subject < ActiveRecord::Base
  validates_inclusion_of :screening, :in => lambda { |subject|
(subject.screened_on + 7.days)..(subject.screened_on + 14.days) }
end

So basically I just want to make sure the date they entered is between
dates the object was screend.

However, I get this error:

.rvm/gems/ruby-1.8.7-p357/gems/activerecord-2.3.10/lib/active_record/
validations.rb:908:in `validates_inclusion_of': An object with the
method include? is required must be supplied as the :in option of the
configuration hash (ArgumentError)

Ok so the source code shows this line:

enum = configuration[:in] || configuration[:within]
607:
608:         raise(ArgumentError, "An object with the method include?
is
required must be supplied as the :in option of the configuration
hash")
unless enum.respond_to?("include?")

Granted, a model instance does not have the include? method. So then
why does the example in the rails documentation work and what can I do
to emulate that?

thanks for response



-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to