1
我在我的ruby應用程序中使用了從http://arshaw.com/fullcalendar開始的Jquery完整日曆。我想爲4種不同類型的事件顯示不同的顏色,例如(假期,學校,工作,娛樂),這些事件保存在我的事件表中作爲type_of_eventJquery FullCalendar-根據ruby應用程序中的even_type更改事件顏色
現在,我只用start_at和end_at使用以下代碼獲取事件:
scope :before, lambda {|end_time| {:conditions => ["ends_at < ?", Event.format_date(end_time)] }}
scope :after, lambda {|start_time| {:conditions => ["starts_at > ?", Event.format_date(start_time)] }}
# need to override the json view to return what full_calendar is expecting.
# http://arshaw.com/fullcalendar/docs/event_data/Event_Object/
def as_json(options = {})
{
:id => self.id,
:title => self.title,
:description => self.description || "",
:start => starts_at.rfc822,
:end => ends_at.rfc822,
:allDay => self.all_day,
:recurring => false,
:url => Rails.application.routes.url_helpers.event_path(id),
#:color => "red"
}
end
def self.format_date(date_time)
Time.at(date_time.to_i).to_formatted_s(:db)
end
是否有根據自己的EVENT_TYPE顯示事件顏色的任何具體的方式意味着,如果事件類型是學校它會告訴我紅色