Reputation: 2304
I'm sorry to ask a stupid question. I've got an array that I want to populate with two similar queries to my database.
@experience_items = @user.experience_items.where(current: true).order(start_date: :desc)
@experience_items << @user.experience_items.where(current: false).order(end_date: :desc)
This is currently returning an ActiveRecord::AssociationRelation
, which I can't iterate through with <% @experience_items.each do |item| %>
I know this is basic, but I just don't understand it. Why can't I iterate through @experience_items?
Upvotes: 0
Views: 43
Reputation: 51171
It's because you add ActiveRecord::Relation
to @experience_items
as an element instead of concatenating these array-like objects. This should work:
@experience_items += @user.experience_items.where(current: false).order(end_date: :desc)
Upvotes: 1