On Oct 30, 9:15 am, Grary Stimon <li...@ruby-forum.com> 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@googlegroups.com.
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.
No comments:
Post a Comment