我有两个活动记录数组。我合并了这两个数组,现在我想根据“updated_at”字段对它们进行排序。未定义的方法`updated_at'为#<MatchResult :: ActiveRecord_Relation:0x0000000232e608> in rails
@notification_challenges=Challenge.where("to_id=? and activity_id=?" ,current_user.id,@activity.id)
@match_results=[]
@notification_challenges.each do |k|
@[email protected]_results<<MatchResult.where("challenge_id=? and result_confirmation_status=?" ,k.id,1)
end
if [email protected]_results.blank?
@[email protected][email protected]_results
end
if [email protected]_challenges.blank?
@[email protected][email protected]_challenges
end
if [email protected]?
@notifications2=(@notifications).sort_by(&:updated_at)
@[email protected]
end
,但它给以下错误:
undefined method `updated_at' for #<MatchResult::ActiveRecord_Relation:0x0000000232e608>
和
@notifications=(@[email protected]_challenges).sort_by(&:updated_at)
工作正常。 但我想检查@match_results或@notification_challenges是否为空,所以我合并这两个数组,然后应用“sort_by”函数。
使用此代码'@ notifications2 =(@ notifications).sort_by {| e | E [:的updated_at]}' –