On Oct 5, 4:42 pm, Dudebot <[email protected]> wrote:
> Here's a question:
>
> I have the exact same validation code in 2 different models.
>
> OK, you're thinking, combine the models.  Not in this case.
>
> So, in Rails, is there a way to reference the same validation for 2
> different models?

Commonly you can find this done with validation plugins.

See for example,

  http://marklunds.com/articles/one/312

for an email address validation, which is then available in all
ActiveRecord models through

class A < ActiveRecord::Base

validates_as_email :email_address

end

Stephan


> E.g.
>
>   validate :foo
>
>   def foo
>     bar
>   end
>
> Appears in /models/a.rb and /models/b.rb
>
> Can I make foo DRY?
>
> TIA,
> Craig
--~--~---------~--~----~------------~-------~--~----~
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