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
As per my knowledge the files in lib directory are not loaded automatically. RAILS includes the
libdirectory in the class path. You have to explicitly load the file if you need it. You can do so by:Adding a
requireto the end ofenvironment.rb, i.e.OR
By adding a initializer file in the
config/initializersdirectory, i.e.config/initializers/load_model_helper.rb