我有这个简单的方法来检查 URL 是否存在,如果不存在,则尝试创建照片对象。
def create_profile_photo(user_id,image_url)
if Photo.find_by_external_url(image_url).blank?
profile_photo = Photo.new
profile_photo.user_id = user_id
profile_photo.picture_from_url(image_url)
profile_photo.save
end
end
# Photo.rb
def picture_from_url(url)
self.external_url = url
self.attachment = URI.parse(clean_url)
end
它确实有效。但是当我尝试使用它启动方法时delayed_job
它不起作用。
ruby-1.9.2-p290 :085 > MyClass.new.delay.create_profile_photo(347,'http://www.google.com/images/srpr/logo3w.png')
(0.4ms) COMMIT
=> #<Delayed::Backend::ActiveRecord::Job id: 42, priority: 0, attempts: 0, handler: "--- !ruby/object:Delayed::ProfileableMethod\nobject:...", last_error: nil, run_at: "2012-12-08 21:40:06", locked_at: nil, failed_at: nil, locked_by: nil, queue: nil, created_at: "2012-12-08 21:40:06", updated_at: "2012-12-08 21:40:06">
ruby-1.9.2-p290 :085 > Photo.count
(0.3ms) SELECT COUNT(*) FROM "photos"
=> 0
任何的想法?