Hi I would like to know the difference between writing our own class file(or module) in lib folder and models folder (Or any other folder). Actually what is the use of this lib folder in rails..Cant I write the same in models folder (not inheriting from ActiveRecord class) Thanks in advance Sijo -- 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 -~----------~----~----~----~------~----~------~--~---
Andrew Timberlake
2009-Apr-09 09:37 UTC
Re: difference in writing a class file in lib and models folder
On Thu, Apr 9, 2009 at 11:26 AM, Sijo Kg <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi > I would like to know the difference between writing our own class > file(or module) in lib folder and models folder (Or any other folder). > Actually what is the use of this lib folder in rails..Cant I write the > same in models folder (not inheriting from ActiveRecord class) > > Thanks in advance > Sijo > -- > Posted via http://www.ruby-forum.com/. > > > >You could but if it''s not a model, why put it in a folder labelled models? It''s purely for code organisation, and Rails uses the folder names for some of it''s auto load magic. I use a library called simple_form which creates a non-ActiveRecord model for contact forms but it behaves like a model as far as Rails is concerned so I will put that class in the models folder. Andrew Timberlake http://ramblingsonrails.com http://www.linkedin.com/in/andrewtimberlake "I have never let my schooling interfere with my education" - Mark Twain --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Julian Leviston
2009-Apr-09 10:01 UTC
Re: difference in writing a class file in lib and models folder
Lib is mostly for your own classes that don''t change much. Hence, in dev mode Theyre not reloaded. Models are. Models can be any classes, inheriting from anywhere. They''re or your business objects Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/ On 09/04/2009, at 7:26 PM, Sijo Kg <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi > I would like to know the difference between writing our own class > file(or module) in lib folder and models folder (Or any other folder). > Actually what is the use of this lib folder in rails..Cant I write the > same in models folder (not inheriting from ActiveRecord class) > > Thanks in advance > Sijo > -- > 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 -~----------~----~----~----~------~----~------~--~---
Andrew Timberlake
2009-Apr-09 10:11 UTC
Re: difference in writing a class file in lib and models folder
On Thu, Apr 9, 2009 at 12:01 PM, Julian Leviston <julian-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote:> > Lib is mostly for your own classes that don''t change much. Hence, in > dev mode Theyre not reloaded. Models are. Models can be any classes, > inheriting from anywhere. They''re or your business objects > > Blog: http://random8.zenunit.com/ > Learn rails: http://sensei.zenunit.com/ >I disagree, a quick test in 2.2.2 shows classes in lib reloading in dev mode Andrew Timberlake http://ramblingsonrails.com http://www.linkedin.com/in/andrewtimberlake "I have never let my schooling interfere with my education" - Mark Twain --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
yes classes in lib reloading in dev mode -- 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 -~----------~----~----~----~------~----~------~--~---
Robert Walker
2009-Apr-10 23:10 UTC
Re: difference in writing a class file in lib and models fo
Andrew Timberlake wrote:> On Thu, Apr 9, 2009 at 11:26 AM, Sijo Kg > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> Posted via http://www.ruby-forum.com/. >> >> > >> > > You could but if it''s not a model, why put it in a folder labelled > models?There is some room for debate here in terms of the definition of a model object. After all in a truly pure sense of the MVC design pattern a model object can be as simple as the String class all the way up to a class a complex as ActiveRecord. After all, what does a String object do? It manages the interface to a set of data, which is the array of characters. It abstracts and encapsulates the storage of that set of data. So in a pure sense it is a model object. That''s the interesting thing about the MVC pattern. There is no absolutes. It all depends on the definitions and usage in particular contexts.> It''s purely for code organisation, and Rails uses the folder names for > some of it''s auto load magic.I completely agree with this. Applying MVC inside the context of Rails will make others that might want to work with you on your code happy. Typically the stuff in app/models are subclasses of ActiveRecord (or other ORM style model classes). And the lib folder is typically used for classes and modules that provide some shared behavior, whether they be "model" objects or not. -- 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 -~----------~----~----~----~------~----~------~--~---