jeudi 23 juillet 2015

Can't call class method within another class

I have two classes found within my lib folder. Both files are found in the lib/services folder. I'm loading the files via this method in my initializer.

['account_helpers', 'facades', 'decorators', 'presenters', 'serializers', 'services', 'views', 'queries'].each do |folder|
  Dir["#{Rails.root}/lib/#{folder}/*.rb"].each {|file| load file}
end

My two classes appear as so...

class MarketingEmail
  def self.send
    User.where('created_at >= ?', 15.days.ago).each do |user|
      MarketingEmailDecider(user).deliver
    end
  end
end

class MarketingEmailDecider < MarketingEmail
  def init(user)
    @user = user
  end

  def deliver
    puts "delivered"
  end
end

Whenever I run the code I get the following error

 NoMethodError:
   undefined method `MarketingEmailDecider' for MarketingEmail:Class

Why is this happening and how can I fix this? I'm having no other issues with running other classes in any of my other classes (if that makes sense).

Aucun commentaire:

Enregistrer un commentaire