ruby on rails - Undefined method 'items_loaded' -


missing fundamental here. getting undefined method 'items_loaded' when trying check if rest client done fetching items api.

live app can run on fly: http://runnable.com/vw9rqx-kiiffmpii/ajax-affiliates

started "/check_items_loaded" @ 2015-06-04 17:03:44 +0000 processing maincontroller#check_items_loaded */* completed 500 internal server error in 2ms (activerecord: 0.0ms)      nomethoderror (undefined method `items_loaded' #<class:0x00000004e694a8>):   app/controllers/main_controller.rb:12:in `check_items_loaded' 

main_controller.rb

class maincontroller < applicationcontroller   def index     # delay fetching     # @products = affiliate.fetch     @products = affiliate.delay.fetch      # let know when fetching done     affiliate.set_items_loaded   end    def check_items_loaded     @items_status = affiliate.items_loaded     respond_to |wants|       wants.js     end   end end 

affiliate.rb

require "rest_client"  class affiliate < activerecord::base   def self.fetch     response = restclient::request.execute(       :method => :get,       :url => "http://api.shopstyle.com/api/v2/products?pid=uid7849-6112293-28&fts=women&offset=0&limit=10"     )      @products = json.parse(response)["products"].map |product|       product = openstruct.new(product)       product     end   end    def self.set_items_loaded     self.update_all(items_loaded: true)   end end 

routes.rb

get '/check_items_loaded', to: 'main#check_items_loaded', as: :check_items_loaded 

20150604120114_add_items_loaded_to_affiliates.rb

class additemsloadedtoaffiliates < activerecord::migration   def self.up     change_table :affiliates |t|       t.column :items_loaded, :boolean, default: false     end   end    def self.down     change_table :affiliates |t|       t.remove :items_loaded     end   end end 

@items_status = affiliate.items_loaded 

items_loaded instance method, not class method.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -