I'm trying to understand a little more of the mysterious ways of rails and I have the following question.
When I am in a class e.g. a model I can call methods directly without putting the method calls inside a method on the model.
For example:
Post < ApplicationRecord
has_many :comments
end
In this case has_many is a method call but its just sitting in my Post class without being inside a method. If I try to do the same thing in a blank ruby project it doesn't work.
for example
class ParentClass
def say_hello
p "Hello from Parent Class"
end
end
class ChildClass < ParentClass
say_hello
end
child = ChildClass.new
# => undefined local variable or method `say_hello' for ChildClass:Class (NameError)
So how does Rails do it? I see it all the time I even see some gems that add these method calls, e.g. acts_as_votable
Can anyone explain whats going on?