Jquery FullCalendar-根据ruby应用程序中的偶数类型更改事件颜色
我正在ruby应用程序中使用Jquery完整日历。我想为4种不同类型的活动显示不同的颜色,例如(假期、学校、工作、娱乐),这些活动被保存在我的事件表中,作为事件的类型 现在,我仅使用以下代码获取start_at和end_at的事件:Jquery FullCalendar-根据ruby应用程序中的偶数类型更改事件颜色,jquery,ruby-on-rails,fullcalendar,Jquery,Ruby On Rails,Fullcalendar,我正在ruby应用程序中使用Jquery完整日历。我想为4种不同类型的活动显示不同的颜色,例如(假期、学校、工作、娱乐),这些活动被保存在我的事件表中,作为事件的类型 现在,我仅使用以下代码获取start_at和end_at的事件: scope :before, lambda {|end_time| {:conditions => ["ends_at < ?", Event.format_date(end_time)] }} scope :after, lambda {|star
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
scope:before,lambda{end_time}{:conditions=>[“end_at<?”,Event.format_date(end_time)]}
作用域:之后,lambda{|开始|时间{:条件=>[“开始时间>?”,事件。格式{u日期(开始时间)]}
#需要覆盖json视图以返回完整的日历。
# http://arshaw.com/fullcalendar/docs/event_data/Event_Object/
def as_json(选项={})
{
:id=>self.id,
:title=>self.title,
:description=>self.description | |“”,
:start=>在.rfc822处启动\u,
:end=>ends\u位于.rfc822,
:allDay=>self.all\u day,
:recurtive=>false,
:url=>Rails.application.routes.url\u helpers.event\u path(id),
#:color=>“红色”
}
结束
定义自身格式\日期(日期\时间)
时间.at(日期时间到时间)。到格式(:db)
结束
是否有任何特定的方式根据事件类型显示事件颜色?表示如果事件类型为学校,它将向我显示红色您打算在模型之外的其他地方使用这些颜色吗 很可能,您不需要使其全局可用,因此只需向模型中添加一个常量:
scope :before, ...
scope :after, ...
EVENT_COLORS = { "School" => "#ff0000", "Holidays" => "#00ff00", ... }
EVENT_COLORS.default = "#0000ff" #optional step, set default color for events
...
:url => Rails.application.routes.url_helpers.event_path(id),
:color => EVENT_COLORS[self.event_type]