给定一个返回 [1, 1] [2, 3], [5,1] 的查询,如何使用该结果?
给定:
class ThreadParticipations
scope :unread, lambda{ |user| where(:user_id => user.id, :read => false) }
end
ThreadParticipations
.unread(current_user)
.includes(:thread => :project)
.group('projects.id')
.count('threads.id')
哪些输出:
=> { 1 => 15, 3 => 10 }
我如何使用该结果来更新我的列表。给出结果集1& 3 是project_ids,我如何迭代该结果来更新列表,例如:
# iterates over @projects
<div>
<li>Project_id 1, unread count = 15</li>
<li>Project_id 2, unread count = 0</li>
<li>Project_id 3, unread count = 10</li>
<li>Project_id 4, unread count = 0</li>
<li>Project_id 5, unread count = 0</li>
</div>
谢谢
Given:
class ThreadParticipations
scope :unread, lambda{ |user| where(:user_id => user.id, :read => false) }
end
ThreadParticipations
.unread(current_user)
.includes(:thread => :project)
.group('projects.id')
.count('threads.id')
Which outputs:
=> { 1 => 15, 3 => 10 }
How do I use that result to update my list. Given in the result set 1 & 3 are project_ids, how can I iterate through that results to update a list like:
# iterates over @projects
<div>
<li>Project_id 1, unread count = 15</li>
<li>Project_id 2, unread count = 0</li>
<li>Project_id 3, unread count = 10</li>
<li>Project_id 4, unread count = 0</li>
<li>Project_id 5, unread count = 0</li>
</div>
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定我是否理解,您只是想迭代哈希来输出 html?
编辑:就这样?
Not sure I understand, you just want to iterate on the hash to output the html?
edit: like that?
首先:您的 HTML 无效。
li
元素位于ul
或ol
内部,而不是div
内部。您要查找的代码是:First off: Your HTML is invalid.
li
elements go insideul
's orol
's, notdiv
's. The code you're looking for is: