I am getting the error "Missing model property.rb" whenever I insert require statements into my model (in this case property.rb). The error occurs when I try to access my application through the browser. As soon as I remove the require, the error no longer occurs. My code is as follows: require ''validation'' require ''date'' require ''time_period'' class Property < ActiveRecord::Base ... Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You should almost never need to require anything in your model; Rails includes a ton of libraries for you. Odd error though, not exactly sure what it means. Jason On 1/26/07, Lee <lee_longmore-/E1597aS9LT10XsdtD+oqA@public.gmane.org> wrote:> > > I am getting the error "Missing model property.rb" whenever I insert > require statements into my model (in this case property.rb). The error > occurs when I try to access my application through the browser. As soon > as I remove the require, the error no longer occurs. > > My code is as follows: > > require ''validation'' > require ''date'' > require ''time_period'' > class Property < ActiveRecord::Base > ... > > Thanks. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
It seems that a corrupt file (validation.rb) was causing the problem. I restored to an older version and the problem went away! I think I need "require" statements for two reasons: 1. to make use of common code under /lib from within my model 2. to access other methods from within a model that "I" have defined in other model files Is this good practice? On 26 Jan, 19:43, "Jason Roelofs" <jameskil...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You should almost never need to require anything in your model; Rails > includes a ton of libraries for you. Odd error though, not exactly sure what > it means. > > Jason > > On 1/26/07, Lee <lee_longm...-/E1597aS9LT10XsdtD+oqA@public.gmane.org> wrote: > > > > > I am getting the error "Missing model property.rb" whenever I insert > > require statements into my model (in this case property.rb). The error > > occurs when I try to access my application through the browser. As soon > > as I remove the require, the error no longer occurs. > > > My code is as follows: > > > require ''validation'' > > require ''date'' > > require ''time_period'' > > class Property < ActiveRecord::Base > > ... > > > Thanks.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You might be overwriting the Rails libraries with those require statements. Since the libraries you are referencing are already loaded up dynamically you need not require them. If there were other libraries that needed to be loaded (ie - ones you wrote) you could do so in your environment.rb, then ''include'' the libraries in the files you need to access them. Keep in mind that require looks in the root directory of where the application is being run from to look for the files to import, that is why you see people using File.dirname(__FILE__) to get the path to the current file instead of the app root. M<>< -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Lee Sent: Friday, January 26, 2007 11:29 AM To: Ruby on Rails: Talk Subject: [Rails] Require in models? I am getting the error "Missing model property.rb" whenever I insert require statements into my model (in this case property.rb). The error occurs when I try to access my application through the browser. As soon as I remove the require, the error no longer occurs. My code is as follows: require ''validation'' require ''date'' require ''time_period'' class Property < ActiveRecord::Base ... Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
So does Rails automatically load the files under /lib and make them visible within all model files? With the exception of the system date.rb, both validation.rb and time_period.rb are in the /lib directory. Also, if I were to define a method ''x'' in my model ''X'' and model ''X'' inherits from ActiveRecord, would the method ''x'' automatically be visible to my code in another ActiveRecord model ''Y''? If so, is this magic by Rails or ActiveRecord? On 26 Jan, 19:59, "Mark Carey" <l...-MMYp1bZq/KasTnJN9+BGXg@public.gmane.org> wrote:> You might be overwriting the Rails libraries with those require statements. > Since the libraries you are referencing are already loaded up dynamically > you need not require them. > > If there were other libraries that needed to be loaded (ie - ones you wrote) > you could do so in your environment.rb, then ''include'' the libraries in the > files you need to access them. > > Keep in mind that require looks in the root directory of where the > application is being run from to look for the files to import, that is why > you see people using File.dirname(__FILE__) to get the path to the current > file instead of the app root. > > M<>< > > -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Lee > Sent: Friday, January 26, 2007 11:29 AM > To: Ruby on Rails: Talk > Subject: [Rails] Require in models? > > I am getting the error "Missing model property.rb" whenever I insert > require statements into my model (in this case property.rb). The error > occurs when I try to access my application through the browser. As soon > as I remove the require, the error no longer occurs. > > My code is as follows: > > require ''validation'' > require ''date'' > require ''time_period'' > class Property < ActiveRecord::Base > ... > > Thanks.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Class in /lib will be automatically require''d by Rails if they follow the following convention: lib/class_name.rb : class ClassName ... end The name of the file must be the underscore version of the name of the class. If the names differ, then you''ll have to require for yourself. Jason On 1/26/07, Lee <lee_longmore-/E1597aS9LT10XsdtD+oqA@public.gmane.org> wrote:> > > So does Rails automatically load the files under /lib and make them > visible within all model files? With the exception of the system > date.rb, both validation.rb and time_period.rb are in the /lib > directory. > > Also, if I were to define a method ''x'' in my model ''X'' and model ''X'' > inherits from ActiveRecord, would the method ''x'' automatically be > visible to my code in another ActiveRecord model ''Y''? If so, is this > magic by Rails or ActiveRecord? > > > On 26 Jan, 19:59, "Mark Carey" <l...-MMYp1bZq/KasTnJN9+BGXg@public.gmane.org> wrote: > > You might be overwriting the Rails libraries with those require > statements. > > Since the libraries you are referencing are already loaded up > dynamically > > you need not require them. > > > > If there were other libraries that needed to be loaded (ie - ones you > wrote) > > you could do so in your environment.rb, then ''include'' the libraries in > the > > files you need to access them. > > > > Keep in mind that require looks in the root directory of where the > > application is being run from to look for the files to import, that is > why > > you see people using File.dirname(__FILE__) to get the path to the > current > > file instead of the app root. > > > > M<>< > > > > -----Original Message----- > > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > > > [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Lee > > Sent: Friday, January 26, 2007 11:29 AM > > To: Ruby on Rails: Talk > > Subject: [Rails] Require in models? > > > > I am getting the error "Missing model property.rb" whenever I insert > > require statements into my model (in this case property.rb). The error > > occurs when I try to access my application through the browser. As soon > > as I remove the require, the error no longer occurs. > > > > My code is as follows: > > > > require ''validation'' > > require ''date'' > > require ''time_period'' > > class Property < ActiveRecord::Base > > ... > > > > Thanks. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---