好的,我有这个电话
location.requests.group_by(&:song)
位置是
>> location = Location.find 4
=> #<Location id: 4, venue: "Rod Laver Arena at Melbourne Park - Melbourne Vic, ...",
showdate: "2010-11-20", created_at: "2010-10-28 01:20:42", updated_at:
"2010-10-28 01:20:42", band_id: nil, artist_name: "Metallica">
location.requests.group_by(&:song)
这个调用返回两个记录“One”和“one”,因为它们以这种方式保存在db中….任何想法如何重做group_by只返回一个记录
我正在使用sqlite
解决方法:
Group_by也可以采用代码块.所以代替:
location.requests.group_by(&:song)
做:
location.requests.group_by{|i| i.song.downcase}
有关相关文档,请参见here.