title: Unable to find items added to database - undefined method `find'
body: <p>Currently fetching some items (<a href="https://github.com/rest-client/rest-client" rel="nofollow">REST Client</a>) from this external API in the background (<a href="https://github.com/collectiveidea/delayed_job_active_record" rel="nofollow">DelayedJob</a>) and then saving them to the database. The plan is to check using a Rails route whether or not the items have been saved to the database, ie. when it's safe to start pulling them in to the client via Ajax.</p>
  
  <p>But how come <code>Affiliate.find(params[:url])</code> in the controller isn't working?</p>
  
  <pre><code>Started GET "/check_items_loaded" at 2015-06-06 00:00:24 +0000
  Processing by MainController#check_items_loaded as */* 
  Completed 500 Internal Server Error in 0ms
  
  NoMethodError (undefined method `find' for Affiliate:Class): 
    app/controllers/main_controller.rb:8:in `check_items_loaded'
  </code></pre>
  
  <p><strong>Live app which you can run on the fly</strong>: <a href="http://runnable.com/VXIdQ6KuRrYPdhKs/rest-client-ajax" rel="nofollow">http://runnable.com/VXIdQ6KuRrYPdhKs/rest-client-ajax</a></p>
  
  <p><strong>routes.rb</strong></p>
  
  <pre><code>get '/check_items_loaded', to: 'main#check_items_loaded', as: :check_items_loaded
  </code></pre>
  
  <p><strong>main_controller.rb</strong></p>
  
  <pre><code>class MainController &lt; ApplicationController
    def index
      # Delay fetching
      @products = Affiliate.delay.fetch
    end
  
    def check_items_loaded
      @items_status = Affiliate.find(params[:url])
      respond_to do |wants|
        wants.js
      end
    end
  end
  </code></pre>
  
  <p><strong>affiliate.rb</strong></p>
  
  <pre><code>require "rest_client"
  
  class Affiliate
    def self.fetch
      response = RestClient::Request.execute(
        :method =&gt; :get,
        :url =&gt; "http://api.shopstyle.com/api/v2/products?pid=uid7849-6112293-28&amp;fts=women&amp;offset=0&amp;limit=10"
      )
  
      @products = JSON.parse(response)["products"].map do |product|
        product = OpenStruct.new(product)
        affiliate = Affiliate.find_or_create_by(:name =&gt; product.name, :url =&gt; product.url)
        affiliate.save
      end
    end
  end
  </code></pre>
  
  <p><strong>20150604213141_add_items_to_affiliates.rb</strong></p>
  
  <pre><code>class AddItemsToAffiliates &lt; ActiveRecord::Migration
    def self.up
      change_table(:affiliates) do |t|
        t.string :name
        t.string :url
      end
    end
  end
  </code></pre>