Note that there are some explanatory texts on larger screens.

plurals
  1. POError when utilizing Gibbon gem via delayed_job?
    text
    copied!<p>Without delayed_job, this code works fine; if I include delayed_job, I get an error of <code>uninitialized constant EmailNewsletter::Gibbon</code> with every attempt the worker makes.</p> <p>Rails 3.0.7, <a href="https://github.com/amro/gibbon">Gibbon</a> 0.1.5 (a gem for working with MailChimp), delayed_job 2.1.4.</p> <p><strong>Controller</strong></p> <pre><code>def subscribe email = params[:email] EmailNewsletter.subscribe(email) render(:update) do |page| page &lt;&lt; "...view update code..." end end </code></pre> <p><strong>lib/email_newsletter.rb</strong></p> <pre><code>module EmailNewsletter def self.subscribe(email) g = Gibbon::API.new('api_key_here', :id =&gt; 'list_id_here') g.listSubscribe(:email_address =&gt; email) end end </code></pre> <p>With the above code, if I post an email address to /subscribe, everything works fine. I want to incorporate delayed_job so that my app doesn't feel slow if MailChimp takes a beat too long to respond.</p> <p><strong>Controller</strong></p> <pre><code>def subscribe email = params[:email] EmailNewsletter.delay.subscribe(email) render(:update) do |page| page &lt;&lt; "...view update code..." end end </code></pre> <p>It looks like the job goes into the delayed_job table just fine. The <code>handler</code> data is:</p> <pre><code>--- !ruby/struct:Delayed::PerformableMethod object: !ruby/module EmailNewsletter method_name: :subscribe args: - email@example.com </code></pre> <p>A second later the worker picks it up and runs, and I get an error: <code>uninitialized constant EmailNewsletter::Gibbon</code>.</p> <p><code>application.rb</code> includes <code>config.autoload_paths += %W(#{Rails.root}/lib)</code>.</p> <p>What am I doing wrong?</p> <p><strong>Edit</strong></p> <p>For clarification, the line that the error is being thrown on is</p> <p><code>g = Gibbon::API.new('api_key_here', :id =&gt; 'list_id_here')</code></p> <p>I have also tried</p> <p><code>g = ::Gibbon::API.new('api_key_here', :id =&gt; 'list_id_here')</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload