I’ve been studing Rails for a not such a long time up to now …. so if there are feel free to correct me
I see that there are two ways of defining methods in rails
def method_name(param)def self.method_name(param)
The difference (as i understand) is that 1 is mainly used in controllers while 2 is used in models… but occasionaly i bump into methods in models that’re defined like 1.
Could you explain to me the main difference of thease two methods?
Number 1. This defines a
instance method, that can be used in instances of the model.Number 2. This defines a
class method, and can only be used by the class itself.Example: