views:

23

answers:

1

I have a rails module included for reference below that I have included using "require 'model_helper' at the bottom of my environment.rb file.

Everything works fine in development, but when I deploy to my nginx/passenger production environment I get an error that the method acts_as_notifiable defined in my model_helper is not found. For some reason the model_helper is not loaded when starting with passenger. The file is called model_helper.rb and is in the lib folder.

    module ActiveRecord
 module ModelHelper # module name
  def self.included(base)
   base.extend(ClassMethods)
  end

  module ClassMethods
   def acts_as_notifiable
    after_create :post_create
    has_one :notification, :as => :about, :dependent => :destroy


   end
   end
  def post_create
   Notification.create :user => user, :about => self unless user.nil?
  end

 end
 end

 ActiveRecord::Base.send :include, ActiveRecord::ModelHelper
+1  A: 

As per my knowledge the files in lib directory are not loaded automatically. RAILS includes the lib directory in the class path. You have to explicitly load the file if you need it. You can do so by:

Adding a require to the end of environment.rb, i.e.

require `model_helper.rb`

OR

By adding a initializer file in the config/initializers directory, i.e.

config/initializers/load_model_helper.rb

require `model_helper.rb`
KandadaBoggu
Thanks, the first does not work by the way in my particular configuration, but the second did. Thanks saved the day. I have not used the initializers folder much before.
Bill Leeper