views:

18

answers:

1

I'm not sure what I'm doing wrong here, I have a file in lib/acts_as_votable.rb, it's just a votable system for the app.

module ActsAsVotable

end

module ActiveRecord
  class Base
    class << self
      cattr_accessor :votable

      def acts_as_votable
        has_many :votes, :as => :voteable
      end

      def votable?
        method_defined? :votes
      end
    end

    def votable?
      self.class.send(:method_defined?, :votes)
    end
  end
end

But it seems that the module never loads:

undefined local variable or method `acts_as_votable' for #<Class:0x00000101796d80>

What would be the proper way to load modules?

+1  A: 

You may put your extensions in the config/initializers directory, so they will be preloaded by Rails automatically.

floatless
hmm... That does work, but is this the best practice?
Joseph Silvashy
I think it is. ` Rails turns to loading initializers. An initializer is any file of ruby code stored under /config/initializers in your application. You can use initializers to hold configuration settings that should be made after all of the frameworks and plugins are loaded.` from http://guides.rubyonrails.org/configuring.html.
floatless