作者:梁言一聚 | 来源:互联网 | 2023-05-17 18:08
IhaveansituationwhereIwanttoshowaneachloopofupdates.Eachupdatehadagameassociate
I have an situation where I want to show an each loop of 'updates'. Each update had a game associated with it (game_id). Some times there are updates that have the same game as other updates. How do I modify the loop so that it only shows unique updates? (in the example code below, I don't want to show the same game thumbnail twice)
我有一种情况,我想显示每个'更新'循环。每次更新都有一个与之相关的游戏(game_id)。有时候有些更新与其他更新具有相同的游戏。如何修改循环以便仅显示唯一更新? (在下面的示例代码中,我不想两次显示相同的游戏缩略图)
In the view:
在视图中:
<% current_user.updates.each do |update| %>
<% end %>
In the updates model
在更新模型中
belongs_to :user
belongs_to :game
In the game model
在游戏模型中
has_many :users
has_many :updates
In the user model
在用户模型中
has_many :updates
2 个解决方案