I am attempting to setup MongoHQ using Heroku and rails 4. I have everything setup correctly to my knowledge, but I'm now getting this error:
uninitialized constant Job::TempEmailContactStoreCsv
This is the Job
model where error is happening:
class Job < ActiveRecord::Base
belongs_to :user
def store_email_contact_csv(file)
contact_array = csv_to_array(file)
TempEmailContactStoreCsv.create(email_contact_array: contact_array, job_id: id)
end
end
And my mongo model:
class TempEmailContactStoreCsv
include Mongoid::Document
field :email_contact_array, type: Array
field :job_id
def self.store(job_id, email_contact_array)
r = TempEmailContactStoreCsv.find_by(job_id: job_id)
if (r.nil?)
TempEmailContactStoreCsv.create!(job_id: job_id, email_contact_array: email_contact_array)
end
end
def self.exists?(job_id)
r = TempEmailContactStoreCsv.find_by(job_id: job_id)
return r.nil? == false
end
def self.retrieve(job_id)
return TempEmailContactStoreCsv.find_by(job_id: job_id)
end
def self.delete(job_id)
r = TempEmailContactStoreCsv.find_by(job_id: job_id)
r.destroy unless r.nil?
end
end
So it seems that my mongo model is not being initialized, and the namespacing seems weird to me also.
Any thoughts as to what is causing this error and how to fix it?
For rails to load a class automatically, the file must be within rails load path (which includes app/models so you are fine there) and the file name should be the camelcased version of the class name.
In your case the file name should be temp_email_contact_store_csv.rb
not temp_email_store_csv.rb