"Helper" function for my models


#1

I’d like to create a validation function that I can use in all of my
models. What’s the best way to create a method that will be available
to all of my models? It looks like Helper methods only work in Views
and methods in the Application class only work in controllers, so how
do I make one for models?

I hope this question isn’t too lame, it seems like something I should
be able to find out on my own but I’ve looked through the book and
online and haven’t been able to figure it out.

Thanks,
Geoff


#2

On 1/26/06, Geoff K. removed_email_address@domain.invalid wrote:

I’d like to create a validation function that I can use in all of my
models. What’s the best way to create a method that will be available
to all of my models? It looks like Helper methods only work in Views
and methods in the Application class only work in controllers, so how
do I make one for models?

I hope this question isn’t too lame, it seems like something I should
be able to find out on my own but I’ve looked through the book and
online and haven’t been able to figure it out.

If you put a file in the /lib/ folder, you can require it in your
model, or in environment.rb.
/your_rails_app/lib/example_helper.rb

require ‘example_helper’
class Example < ActiveRecord::Base

stuff here.

end