Hi All,
I am new to Ruby and ROR
I were trying to create small DSL for conditional validations
valid_with_cond :bypass_validation do
if self.addresses > 3
errors[:base] << "Can not have more than 3 addresses".
end
end
By this I wanted to create array of method and call them all in custom
validation method.
this above code I wanted to do
attr_accessor :bypass_validation
def svalid_cond
unless bypass_validation
if self.addresses > 3
errors[:base] << "Can not have more than 3 addresses".
end
end
end
This way I want in new and edit form I can ask user to click
:bypass_validation attribute and I will bypass this validation.
I tried to create
def valid_with_cond(name, &block)
attr_accessor name
define_method "svalidator_#{name}" do |*arg|
if send name
yield *arg
end
end
end
But after trying it in
Class Person < ActibeRecord::Base
valid_with_cond :test do
if self.addresses > 3
errors[:base] << "Can not have more than 3 addresses".
end
end
end
But when I check it on console
Person.test
it throw me error test is private method.
Anybody could let me know how to correct it.
--
Regards,
-sharad
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.