Hi there,
I need to execute a method in the Rails console (in prod mode).
I tried like this:
My_whateverController.whatevermethod
But it gave me a:
NoMethodError: undefined method `whatevermethod’ for
My_whateverController:Class
What am I missing? Are methods not to be called like this in the
console?
Thanks a lot for your help!
Tom
Tom Ha wrote:
Hi there,
I need to execute a method in the Rails console (in prod mode).
I tried like this:
My_whateverController.whatevermethod
But it gave me a:
NoMethodError: undefined method `whatevermethod’ for
My_whateverController:Class
What am I missing? Are methods not to be called like this in the
console?
Thanks a lot for your help!
Tom
If you defined the method as :
def self.whatevermethod
code here
end
Then the way you called it is correct.
However, you may need to define an instance of the class first:
class My_whateverController
def whatevermethod
code here
end
end
a = My_whateverController.new
a.whatevermethod
Thanks a lot !
(It was the “self.” that was needed in the “def”.)