Forum: Ruby on Rails Helper methods for ActiveRecord

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
78427ee90a59964d712126507c6bf4a0?d=identicon&s=25 Harm Aa (harm)
on 2006-03-11 11:19
Hi all,
I have several models which all have an email field. This email address
should of course be validated and for that I have this nice regex. But
now I have the email validation method copied throughout my different
models. Which is clearly stupid. I figured I needed a helper (module?)
and use this helper I my models. But I can't seem to find anyway of
helpers for models, only for the controllers and views. Am I missing
something here?
Any help is greatly appreciated.

Harm
F59329dc91cba06600ff65c85fd3e93c?d=identicon&s=25 Anthony Green (acgreen)
on 2006-03-11 13:32
Harm aa wrote:
> Hi all,
> I have several models which all have an email field. This email address
> should of course be validated and for that I have this nice regex. But
> now I have the email validation method copied throughout my different
> models. Which is clearly stupid. I figured I needed a helper (module?)
> and use this helper I my models. But I can't seem to find anyway of
> helpers for models, only for the controllers and views. Am I missing
> something here?
> Any help is greatly appreciated.
>
> Harm

I've put mine in environment.rb as a constant and then just refer to in
in my model validation.

_Tony
A63764f318f10379c8b51349b757cf4b?d=identicon&s=25 Jay Levitt (Guest)
on 2006-03-11 19:49
(Received via mailing list)
On Sat, 11 Mar 2006 13:32:41 +0100, Anthony Green wrote:

> Harm aa wrote:
>> But I can't seem to find anyway of
>> helpers for models, only for the controllers and views. Am I missing
>> something here?
>> Any help is greatly appreciated.
>
> I've put mine in environment.rb as a constant and then just refer to in
> in my model validation.

For more complicated cases, there are two ways to do it: inherit your
models from a common class, or put your helper functions into a mixin.
See:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/...

Jay Levitt
78427ee90a59964d712126507c6bf4a0?d=identicon&s=25 Harm Aa (harm)
on 2006-03-12 11:06
Excellent! I should have thought of that. Thanks a lot.
This topic is locked and can not be replied to.