0
icalendar gemを使用して、任意の公開GoogleカレンダーICSエクスポートを解析し、それらをRailsアプリケーションに表示します。問題は、イベントが逆アルファベット順に表示されていることです。私は開始時刻(dtstart)で時間順にソートする方法を理解しようとしています。Ruby/Rails:dtstartでicalendarファイルのデータをソートする方法は?
コントローラー:
require 'icalendar'
require 'net/https'
uri = URI('https://calendar.google.com/calendar/ical/7d9i7je5o16ec6cje702gvlih0hqa9um%40import.calendar.google.com/public/basic.ics')
# above is an example calendar of Argentinian holidays
# the actual calendar would theoretically have hour/minute start/end times
calendar = Net::HTTP.get(uri)
cals = Icalendar::Calendar.parse(calendar)
cal = cals.first
@holidays = cal.events
ビュー:
<% @holidays.each do |x| %>
<div class="event">
<div class="event-title"><strong><%= x.summary.upcase %></strong></div>
<div class="event-room">Room <%= x.location %><span class="event-time"><%= x.dtstart.strftime('%I:%M%p') + ' to ' + x.dtend.strftime('%I:%M%p') %></span>
</div>
</div>
<% end %>
これは逆のアルファベット順ではなく、(好ましくはDTSTARTによる)時系列順にDOMにレンダリングするイベントになります。
ICalendar
内のsort_by!
メソッドは未定義です。