RoR: recognizing a defined class

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

On 8/4/06, Victor [email protected] 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!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs