ruby on rails - Delayed_job does nothing : TypeError: can't convert nil into String -


follow delayed_job "https://github.com/collectiveidea/delayed_job". may know why delayed_job nothing? ran "rake jobs:work" ad got these errors

error:

company#update_count_without_delay failed typeerror: can't convert nil string - 2 failed attempts 

done:

  1. added "gem 'delayed_job_active_record'" gemfile
  2. in console: "rails generate delayed_job:active_record"
  3. in console: "rake db:migrate"

i followed instruction:

if method should run in background, can call #handle_asynchronously after method declaration:  class device   def deliver     # long running method   end   handle_asynchronously :deliver end  device = device.new device.deliver 

model:

require 'json' require 'net/http' require 'rubygems' require 'delayed_job'  class company < activerecord::base before_save :validate_fbid  scope :toplikes, order("count desc").limit(20)  attr_accessible :desc, :fbid, :name, :url, :count  url_regex = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/    validates :name,    :presence   => true  validates :url,     :presence   => true,                 :format     => { :with => url_regex },                 :uniqueness => { :case_sensitive => false } validates :fbid,    :presence   => true validates :desc,    :presence   => true  def update_count     uri = uri("http://graph.facebook.com/" + fbid)     data = net::http.get(uri)     self.count = json.parse(data)['likes'] end  handle_asynchronously :update_count      end  

controller:

def create      company = company.new(params[:company])      if company.save          @message = "new company created."         company.update_count         redirect_to root_path     else          @message = "company create attempt failed. please try again."         redirect_to new_path      end                end  
  1. added "require 'delayed_job'" @ top of model
  2. restart server

you have error in company#update_count. should be:

def update_count   uri = uri("http://graph.facebook.com/" + fbid)   data = net::http.get(uri)   # here should use local variable set in previous line   # instead of unset instance variable:   update_attribute(:count, json.parse(data)['count']) end 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -