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?
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’