I have some validations that need to include an :if clause using the
Class and not the model.
Sounds reasonably straight forward at first by doing this:
validates_presence_of :field_one, :field_two, :if =>
Proc.new{|MyClass| MyClass.feature_is_enabled}
And that works. The problem occurs when I do mor ethan one validation
that way.
validates_presence_of :field_one, :field_two, :if =>
Proc.new{|MyClass| MyClass.feature_is_enabled}
validates_numericality_of :field_three, :field_four, :if =>
Proc.new{|MyClass| MyClass.feature_is_enabled}
That generates a "constant already defined" error. I suspect it has to
be complaining about the |MyClass| part, but I can''t think of what else
to do there.
Any ideas? Thx.
-- gw
--
Posted via http://www.ruby-forum.com/.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
just modify the condition as follows:
:if => Proc.new{|my_class| MyClass.feature_is_enabled}
(or)
:if =>Proc.new{|whatever| MyClass.feature_is_enabled}
The problem is you used MyClass as constant instead of variable. Just
using the lowercase letter will solve ur problem.
--
Regards,
T.Veerasundaravel.
http://tinyurl.com/25vma7h
@veerasundaravel
--
Posted via http://www.ruby-forum.com/.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Veera Sundaravel wrote:> just modify the condition as follows: > > :if => Proc.new{|my_class| MyClass.feature_is_enabled} > (or) > :if =>Proc.new{|whatever| MyClass.feature_is_enabled} > > The problem is you used MyClass as constant instead of variable. Just > using the lowercase letter will solve ur problem.Duh, that makes sense. I was stuck on needing to pass the class name in, which even if that were the case, this isn''t how to do it anyway. Brain spasm. Thx. -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.