Hi Everyone,
-
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.
-
How to access Params[][] & session[] variable in a model?
Please help me out in these issues.
Regards,
VASANTH
- 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
- 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
On Feb 7, 2008 9:36 AM, Vasanthakumar C.
On 7 Feb 2008, at 14:36, Vasanthakumar C. wrote:
Hi Everyone,
- 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.
- 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