If you have methods that you want to make available in a number of
classes, you should put these methods in a module and have each class
''include'' this module, i.e.
in RAILS_ROOT/lib/my_module.rb (you''ll want to
''require'' this file in
environment.rb too, probably)
module MyModule
def calculate_meaning_of_life
6 * 7
end
end
... then in your model objects:
RAILS_ROOT/app/models/model_alpha.rb
class ModelAlpha < ActiveRecord::Base
include MyModule
...
end
RAILS_ROOT/app/models/model_beta.rb
class ModelBeta < ActiveRecord::Base
include MyModule
...
end
... and so on.
- james
On 11/25/05, Larry White <ljw1001-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> If I have ruby code that I need to share among a number of model classes,
> what''s the "right" place to put it form a Ruby
standpoint?
>
> The code provides support for various calculations. It has no data
> elements that are persisted in a database. It seems like there should be
> something like a helpers directory for models for this kind of supporting
> code.
>
> thanks for your help.
> -larry
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>