Reputation: 2279
I want to loop through each item in an array, but the last variable could be an array itself:
<% [@in_force_item, @draft_item,@historical_items].compact.each do |item| %>
it seems to fail at this line:
<td>
<%= datetime_to_string item.updated_at %>
</td>
Is it because the historical_items is actually an array?
Upvotes: 1
Views: 40
Reputation: 1318
Yes, you can't call .updated_at
on the array. Just flatten the array before your iteration:
<% [@in_force_item, @draft_item,@historical_items].compact.flatten.each do |item| %>
Upvotes: 3