[Rails] "Helper" function for my models
Wilson Bilkovich
wilsonb at gmail.com
Thu Jan 26 23:18:42 GMT 2006
On 1/26/06, Geoff Kloess <geoff.kloess at gmail.com> 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
More information about the Rails
mailing list