so i’ve got one pretty simple method in a model here:
def log
self.statistics.build()
self.save
return
end
now i wanted to exclude this method into a module to use it in different models.
module Statistic
def log
self.statistics.build()
self.save
return
end
end
i added the file to the autoload paths and included it into my model (the inclusion works fine).
class Foo < ActiveRecord::Base
include Statistic
end
trying to call the .log method results in an error:
undefined methodnew’ for Statistic:Modulethe raised line number is theself.statistics.build()` line.
any ideas why this is not working?
thanks for all hints! please leave a comment if something is unclear.
I think this is a naming clash.
It seems you have a
has_many :statistics, by default this will look for a class calledStatistic.But this is the same name as the module you have created.
I suggest renaming your module to
StatisticsExtensionsor something of that sort.