Hi all, I am very new to Ruby and I have a silly question: how do I get RoR to "recognize" that I just defined a class? To be more explicit, I have a controller and view, and then I want to create a class and get the controller to "see" it. So, I created a file called "myobject.rb" in the models/ directory and inside it defined "class myobject [...] end". However, if I put code inside the controller that wants to create a new object myobject.new, it says "undefined constant myobject". Any suggestions why Rails doesn''t "see" the class I added? Thanks Vic -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060804/38e5c618/attachment.html
On 8/4/06, Victor <bluestar007@gmail.com> wrote:> Hi all, > I am very new to Ruby and I have a silly question: how do I get RoR to > "recognize" that I just defined a class? To be more explicit, I have a > controller and view, and then I want to create a class and get the > controller to "see" it. So, I created a file called " myobject.rb" in the > models/ directory and inside it defined "class myobject [...] end". However, > if I put code inside the controller that wants to create a new object > myobject.new, it says "undefined constant myobject". Any suggestions why > Rails doesn''t "see" the class I added?Put the class into lib/myobject.rb. Then, in config/environment.rb, put at the end: require ''myclass'' Joe
Thanks a lot! On 8/4/06, Joe Van Dyk <joevandyk@gmail.com> wrote:> > On 8/4/06, Victor <bluestar007@gmail.com> wrote: > > Hi all, > > I am very new to Ruby and I have a silly question: how do I get RoR to > > "recognize" that I just defined a class? To be more explicit, I have a > > controller and view, and then I want to create a class and get the > > controller to "see" it. So, I created a file called " myobject.rb" in > the > > models/ directory and inside it defined "class myobject [...] end". > However, > > if I put code inside the controller that wants to create a new object > > myobject.new, it says "undefined constant myobject". Any suggestions why > > Rails doesn''t "see" the class I added? > > Put the class into lib/myobject.rb. > > Then, in config/environment.rb, put at the end: > require ''myclass'' > > Joe >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060804/7b8a5a4d/attachment.html