Ruby on rails Resque中出现TypeError,我无法找出原因
我有一个后台任务,它发送一封由Resque处理的电子邮件,该邮件抛出了一个TypeError,我无法找出是什么导致了它 我将任务排队:Ruby on rails Resque中出现TypeError,我无法找出原因,ruby-on-rails,ruby,ruby-on-rails-3,debugging,resque,Ruby On Rails,Ruby,Ruby On Rails 3,Debugging,Resque,我有一个后台任务,它发送一封由Resque处理的电子邮件,该邮件抛出了一个TypeError,我无法找出是什么导致了它 我将任务排队:Resque.enqueue(ShownUpvoteEvent,self.id) 然后我在worker中处理它: class ShownUpvoteEvent @queue = :email def self.perform(event_id) UserMailer.shown_upvote_event(event_id).deliver en
Resque.enqueue(ShownUpvoteEvent,self.id)
然后我在worker中处理它:
class ShownUpvoteEvent
@queue = :email
def self.perform(event_id)
UserMailer.shown_upvote_event(event_id).deliver
end
end
调用UserMailer
会触发此方法:
def shown_upvote_event(event_id)
@event = TimelineEvent.find(event_id)
@user = @event.subject
@actor = @event.actor
@song = @event.secondary_subject
if VideoVote.find_by_user_id_and_video_id(@actor.id, @song.id).value == 1
@voted = "upvoted"
else
@voted = "downvoted"
end
mail(:to => @user.email, :subject => "#{@actor.name} #{@voted} the song you showed to him/her.")
end
Resque显示我成功地将事件对象的id传递到worker中,但是我不知道是什么导致了这个错误TypeError
错误
无法将字符串转换为整数。
这是堆栈跟踪:
/app/app/mailers/user_mailer.rb:60:in `[]'
/app/app/mailers/user_mailer.rb:60:in `shown_upvote_event'
/app/.bundle/gems/ruby/1.9.1/gems/actionpack-3.0.7/lib/abstract_controller/base.rb:150:in `process_action'
/app/.bundle/gems/ruby/1.9.1/gems/actionpack-3.0.7/lib/abstract_controller/base.rb:119:in `process'
/app/.bundle/gems/ruby/1.9.1/gems/actionpack-3.0.7/lib/abstract_controller/rendering.rb:41:in `process'
/app/.bundle/gems/ruby/1.9.1/gems/actionmailer-3.0.7/lib/action_mailer/old_api.rb:75:in `process'
/app/.bundle/gems/ruby/1.9.1/gems/actionmailer-3.0.7/lib/action_mailer/base.rb:471:in `process'
/app/.bundle/gems/ruby/1.9.1/gems/actionmailer-3.0.7/lib/action_mailer/base.rb:466:in `initialize'
/app/.bundle/gems/ruby/1.9.1/gems/actionmailer-3.0.7/lib/action_mailer/base.rb:450:in `new'
/app/.bundle/gems/ruby/1.9.1/gems/actionmailer-3.0.7/lib/action_mailer/base.rb:450:in `method_missing'
/app/app/workers/send_emails.rb:46:in `perform'
堆栈跟踪指向第60行真的很奇怪,因为似乎不应该调用代码:
def heard_event(event_id)
@event = TimelineEvent.find(event_id)
@user = @event.subject
@actor = @event.actor
@song = @event.secondary_subject
showable_video = ShowableVideo.find_by_user_id_and_profile_id_and_video_id(@user.id, @actor.id, @song.id)
if showable_video.heard == true
@heard = "had already heard"
else
@heard = "had not yet heard"
end
#below is line 60, but this method should not be running
mail(:to => @user.email, :subject => "#{@actor.name} #{@heard} the song you showed to him/her.")
end
def shown_upvote_event(event_id)
@event = TimelineEvent.find(event_id)
@user = @event.subject
@actor = @event.actor
@song = @event.secondary_subject
if VideoVote.find_by_user_id_and_video_id(@actor.id, @song.id).value == 1
@voted = "upvoted"
else
@voted = "downvoted"
end
mail(:to => @user.email, :subject => "#{@actor.name} #{@voted} the song you showed to him/her.")
end
@SergioTulentsev我更新了问题的详细信息你确定这是第60行,而不是在修改代码之后吗?运行
VideoVote.find_by_user_id_和\u video_id(@actor.id,@song.id).class.name
。是否返回String
?检查。(假设<代码>如果<代码>在第60行。)和主题之外,也许<代码>“{@actor.name}{@heard}你分享的歌曲。”可能更好?@SergioTulentsev是的,这是真正的第60行,除非我疯了