Hey all!

Hope you're having a good weekend.

I have a couple of models that share a lot of similar validation so I
figured this would be a good opportunity to DRY my code up.

lets say for example:

class Squirrel < ActiveRecode::Base

  validates_presence_of :name

end

class Badger < ActiveRecode::Base

  validates_presence_of :name

end

what I've been trying to do is add a module in /lib called
CommonValidations

module CommonValidations

  def included(base)
    base.class_eval do
      validates_presence_of :name
    end
  end
end

and then include this module in the models that require it. I've also
tried various combinations with 'eval' and 'send' etc.

The validations aren't called :(

Can anyone explain why this isn't working and if it's possbile to re-
use validations like this?

Thanks

Gavin
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to