我有这个类,它的响应由“Resque”运行,我在这一行有一个错误recipient.response = response.body
:
#Hash:0x00000003969da0 的未定义方法 response='
我认为这是因为工人和 ActiveRecord 不能一起工作。
PS我已经加载了我的环境和这个类放在lib目录中
使用:
Ruby 1.9.2
Rails 3
Resque 1.10.0
class Msg
def self.perform(message,sender,host, path, recipient)
message_logger ||= Logger.new("#{Rails.root}/log/message.log")
response = Net::HTTP.get_response(host, path)
begin
recipient.response = response.body
recipient.sent_at = Time.zone.now
recipient.save
# Logging
log = "Message #{
message.sent_at}\n\tRespone:\n\t\tBody: #{response.body}\n\t\tCode: #{response.code}\n"
message_logger.info(log)
rescue Exception => e
message_logger.error(e.message + '/n' + e.backtrace.inspect)
end
end
end