我昨天从Rails 3.2.3更新到3.2.8。
这个脚本一直工作到昨天。现在我收到这个错误:
/daily_counts.rb:32:in `<main>': undefined method `each' for 4294:Fixnum (NoMethodError)
top_posters = Load.where("created_at >= '#{today}' AND comments NOT LIKE '%Post%'").count(:all, group: "user_id", order: "COUNT(*) DESC", limit: 8)
output += "Loadmax Totals\n\s\sAll Avaliable Trucks: #{alltrucks}\n\s\sAll Avaliable Loads: #
{allloads}\n\s\sTodays Loads: #{loads}\n\s\sTodays Trucks: #{trucks}\n\nLoadmax Top Posters\n\s\sPostEverywhere: #{posteverywhere}\n\s\sPostOnce: #{postonce}\n"
posters = "\s\s"
LINE 32: Below
top_posters.each do |k,v|
company_name = Company.find(User.find(k).company_id).name unless k.nil?
poster = {
name: company_name,
posts: v
}
poster[:name] = 'MISC' if poster[:name].nil?
posters += "#{poster[:name]}: #{poster[:posts]}\n\s\s"
end
output += posters.chop.chop.chop
output += "\n\s\s"
users = "\s\s"
使用完整的脚本。发送电子邮件看起来像这样:
Total Active Loads/Trucks for Today or FutureLast 24 hours Users Logged In: 0
Loadmax Totals
All Avaliable Trucks: 409
All Avaliable Loads: 150799
Todays Loads: 78316
Todays Trucks: 169
Loadmax Top Posters
PostEverywhere: 70374
PostOnce: 2974
AMTransportServices.Inc: 2130
TNT Trucking of the Carolinas LLC: 1099
JM: 425
BOYD: 412
DANDL: 327
bijDHhgvsiKBa: 180
MTB: 177
Ultra Logistics: 131
digihaul@digihaul.com
Last Login Date 2014-06-16
Logins: 23
答案 0 :(得分:1)
未定义的方法`每个&#39;对于4294:Fixnum(NoMethodError)
错误是由于 top_posters
是4294,这是 integer
,因为目前它返回 {{1} } 。通过整数 count
或 can't iterate
。
如果您希望循环 loop
,则可能是 top_posters
或 array
因此,您需要根据自己的要求修改查询,以便 hash
为 top_posters
或 {{ 1}} 强>