Wes Gamble
2006-Jul-18 17:38 UTC
[Rails] validate method doesn''t recognize another instance method
All,
I am attempting to do some custom validation on my object.
Here is my validate method:
protected
def validate
puts "Do I have the target_list_ids method? " +
self.methods.include?(''target_list_ids'').to_s
if target_list_ids.nil? || target_list_ids.length == 0
errors.add_to_base("You must choose at least one target list for
this job")
end
puts "Do I have the Fax method? " +
self.methods.include?(''Fax'').to_s
if Fax.nil?
errors.add_to_base("You must choose at least one report
destination (either email or fax) for this job")
end
# puts "checking"
# puts Fax.nil?
# puts EMAIL.nil?
# puts "EMAIL: #{EMAIL}"
# if ((Fax.nil?) || (Fax == '''')) && ((EMAIL.nil?)
|| (EMAIL == ''''))
#
# end
end
--
Posted via http://www.ruby-forum.com/.
Wes Gamble
2006-Jul-18 17:43 UTC
[Rails] validate method doesn''t recognize another instance method
All,
I am attempting to do some custom validation on my object.
Here is my validate method:
protected
def validate
puts "Do I have the target_list_ids method? " +
self.methods.include?(''target_list_ids'').to_s
if target_list_ids.nil? || target_list_ids.length == 0
errors.add_to_base("blah")
end
puts "Do I have the Fax method? " +
self.methods.include?(''Fax'').to_s
if Fax.nil?
errors.add_to_base("blah")
end
end
and here is the output:
Do I have the target_list_ids method? true
Do I have the Fax method? true
uninitialized constant Fax
So as you can see, I am calling the target_list_ids method without
incident but can''t seem to call the Fax method, which I just showed as
existing.
Can anyone explain to me why my "Fax" method can''t be called
in the same
way that my "target_list_ids" method can?
I''ll be reading the validate method.
I love this API where I get to read every bit of source code - it really
enhances my productivity ;).
Thanks,
Wes
--
Posted via http://www.ruby-forum.com/.
Wes Gamble
2006-Jul-18 17:48 UTC
[Rails] Re: validate method doesn''t recognize another instance metho
Wes Gamble wrote:> All, > > I am attempting to do some custom validation on my object. > > Here is my validate method: > > protected > def validate > puts "Do I have the target_list_ids method? " + > self.methods.include?(''target_list_ids'').to_s > > if target_list_ids.nil? || target_list_ids.length == 0 > errors.add_to_base("blah") > end > > puts "Do I have the Fax method? " + > self.methods.include?(''Fax'').to_s > if Fax.nil? > errors.add_to_base("blah") > end > end > > and here is the output: > > Do I have the target_list_ids method? true > Do I have the Fax method? true > uninitialized constant Fax > > So as you can see, I am calling the target_list_ids method without > incident but can''t seem to call the Fax method, which I just showed as > existing. > > Can anyone explain to me why my "Fax" method can''t be called in the same > way that my "target_list_ids" method can? > > I''ll be reading the validate method. > > I love this API where I get to read every bit of source code - it really > enhances my productivity ;). > > Thanks, > WesI notice that if I put parens after Fax, so if Fax().nil?, it seems to work. However, why do I have to put parens after one method name but not the other? Oh my God, it''s because Fax is capitalized, isn''t it? Oh boy... Thanks, Wes -- Posted via http://www.ruby-forum.com/.