Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Resque中出现TypeError,我无法找出原因_Ruby On Rails_Ruby_Ruby On Rails 3_Debugging_Resque - Fatal编程技术网

Ruby on rails 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处理的电子邮件,该邮件抛出了一个TypeError,我无法找出是什么导致了它

我将任务排队:
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行,除非我疯了