如何在模型中显示按日期分隔的表格
使用 Enumerable,我尝试按日期在有组织的事件日历中显示日期。不是标准的 7 格日历。
尝试获取:
2011 年 12 月 1 日 活动1 活动2 活动 3
2011 年 12 月 2 日 活动4 活动 5
2011 年 12 月 3 日 事件 6
...
目前 Enumerable 让我很困惑。感谢您的任何指导
- 编辑 2011 年 12 月 22 日
当前数据:
控制器字符串 -
@events = Event.where('start >= ?', Date.today).paginate(:per_page => 15, :page => params[:page])
视图调用 -
<% @events.each do |event| %>
<table stuff here>
<% end %>
方法 - 到目前为止尚未指定任何可枚举的方法 -
我的表包括以下字段; :title、:venue、:address(已地理编码)、:about(文本)、:start(日期时间函数)
Using Enumerable, I am trying to display dates in an organized event calendar by dates. Not as a standard 7 grid calendar.
Trying to get:
December 1, 2011
Event 1
Event 2
Event 3
December 2, 2011
Event 4
Event 5
December 3, 2011
Event 6
...
Currently Enumerable confuses the hell outta me. Thanks for any guidance--
EDIT Dec.22,2011
Current Data:
Controller string-
@events = Event.where('start >= ?', Date.today).paginate(:per_page => 15, :page => params[:page])
View call-
<% @events.each do |event| %>
<table stuff here>
<% end %>
Method- Have not specified anything enumerable on method as of now---
My table includes the following fields; :title, :venue, :address (is geocoded), :about (text), :start (datetime function)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新问题更新:因此,您在
@events
中有一堆事件对象,因此您可以使用group_by
:这将为您提供
@events_by_date
中带有日期的哈希值作为钥匙和Event 对象的数组作为值。然后,您需要一个日期数组的数组来匹配您的月份并从该数组驱动表:
当然会涉及一些格式,但结构是相似的。
Update for question update: So you have a bunch of event objects in
@events
so you could use agroup_by
:That would give you a Hash in
@events_by_date
with dates as the keys and arrays of Event objects as the values.Then you'd want an array of arrays of Dates to match your month and drive the table from that array:
There would be some formatting involved of course but the structure would be similar.