Common Functions for Models

Hi Everyone,

1) Can anyone tell me where to put the common functions, which is to be
used in more than one model & controller? Is there any way to create a
"common_functions.rb" model?
(Or)
is it a good practice to put all the common functions (functions with or
without database activities) in Application controller? since
Application controller is accessible anywhere.

2) How to access Params[][] & session[] variable in a model?

Please help me out in these issues.

Regards,
VASANTH

1) Library that gets put in lib/:

lib/common_functions.rb:
module CommonFunctions # or class
  ... Your stuff here ...
end

In your model:

CommonFunctions.method, or you can include CommonFunctions

2) The controller should send to the model only the information it
needs. Models do not know about params / session for a very good
reason.

Jason

Hi Everyone,

1) Can anyone tell me where to put the common functions, which is to
be
used in more than one model & controller? Is there any way to create a
"common_functions.rb" model?

You can create modules and include them where appropriate. It may be
appropriate to put some things in application controller - eg all our
controllers require you to be logged in, so the stuff to do with that
is handled at the application controller

(Or)
is it a good practice to put all the common functions (functions
with or
without database activities) in Application controller? since
Application controller is accessible anywhere.

2) How to access Params[][] & session[] variable in a model?

pass them (or relevant subsets thereof) down as parameters

Fred

Thanks a lot for your solutions.

Regards,
VASANTH