1

I'm trying to write a gem that extends the methods available to ActiveRecord models. At this point it's super simple, and only consists of 3 files, per following the instructions listed on this question: Rails extending ActiveRecord::Base and using Railties to self-initilize.

my_gem.rb

require 'my_gem/railtie' if defined? ::Rails::Railtie

my_gem/railtie.rb

require 'my_gem/extensions'
module MyGem
  class Railtie < ::Rails::Railtie
    initializer "my_gem.extensions" do
      ActiveSupport.on_load(:active_record) do
        ActiveRecord::Base.send :include, Extensions
      end 
    end
  end
end

my_gem/extensions.rb

module MyGem
  module Extensions
    extend ActiveSupport::Concern

    module ClassMethods

      def in_the_past_x_days x = 14
        where("#{self.table_name}.created_at > ?", x.days.ago)
        .group("DATE(#{self.table_name}.created_at)")
      end

    end
  end
end

This results in a "NoMethodError", however, whenever I try to call in_the_past_x_days. Am I missing something obvious?

Update

Turns out it was something obvious, see answer for details.

Community
  • 1
  • 1
Jonathan Bender
  • 1,911
  • 4
  • 22
  • 39

1 Answers1

0

This gem was being built to complement the functionality of another gem in development, which wasn't being updated properly (the gem had to be specified in the parent with the github address in order to reference the local files).

Jonathan Bender
  • 1,911
  • 4
  • 22
  • 39