@experience_items = @user.experience_items.where(current: true).order(start_date: :desc)
@experience_items << @user.experience_items.where(current: false).order(end_date: :desc)
目前返回ActiveRecord::AssociationRelation
,我无法通过<% @experience_items.each do |item| %>
我知道这是基本的,但我不理解。为什么我不能遍历@experience_items?
答案 0 :(得分:1)
这是因为您将ActiveRecord::Relation
添加到@experience_items
作为元素,而不是连接这些类似数组的对象。这应该有效:
@experience_items += @user.experience_items.where(current: false).order(end_date: :desc)