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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Feb 7, 2008 9:36 AM, Vasanthakumar Csk <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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 > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 7 Feb 2008, at 14:36, Vasanthakumar Csk wrote:> > 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> Please help me out in these issues. > > Regards, > VASANTH > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks a lot for your solutions. Regards, VASANTH -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---