Hey, I''m trying to specify validations with ActiveModel::Validations at the module level, i.e., I wish to mix-in validations to a module. I am not succeeding at this, however. How do I mix-in ActiveModel::Validations into another module and use its methods just as I would in a class? Thanks, L -- 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.
On Oct 29, 9:47 pm, Grary Stimon <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hey, > > I''m trying to specify validations with ActiveModel::Validations at the > module level, i.e., I wish to mix-in validations to a module. I am not > succeeding at this, however. How do I mix-in ActiveModel::Validations > into another module and use its methods just as I would in a class? >I''m not sure what you mean. Do you want want to put a shared set of validations in a module or create a module that when included adds a set of validations (among other things) Fred> Thanks, > > L > > -- > Posted viahttp://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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick, I seek to create Ruby modules that use ActiveModel::Validations. The examples I have seen of ActiveModel::Validations all involve including that module in classes. This is not what I want. I want to involve the use of ActiveModel::Validations in a module, which I may then choose to implement as a ruby class (even if after a few more descents via other modules.) In short, how do I do get to do the following (or its equivalent) in a module? validates :some_attribute, :numericality_of=>{:greater_than => 0, :allow_blank=>true} G -- 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.
On Oct 30, 9:15 am, Grary Stimon <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick, > > I seek to create Ruby modules that use ActiveModel::Validations. The > examples I have seen of ActiveModel::Validations all involve including > that module in classes. This is not what I want. I want to involve the > use of ActiveModel::Validations in a module, which I may then choose to > implement as a ruby class (even if after a few more descents via other > modules.) > > In short, how do I do get to do the following (or its equivalent) in a > module? > > validates :some_attribute, :numericality_of=>{:greater_than => 0, > :allow_blank=>true}I think ActiveSupport::Concern is what you''re looking for here - you could create a module that defines validations like this: module SomeModule extend ActiveSupport::Concern include ActiveModel::Validations included do validates :some_attribute, ... end end --Matt Jones -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Matt, Thanks, that did the trick, and I think it unlikely that I would have found that without some help! Now, on to what is likely the subject of yet another post: How do I obtain the effect of ActiveModel::Validations#validates_associated if applied to non-ActiveRecord classes where I seek to obtain nested validations when the given class is composed of multiple Ruby objects... G -- 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.