I'm using Jquery full calendar from http://arshaw.com/fullcalendar in my ruby apps. I wanna show different color for 4 different kind of events like (Holidays, School, Work, Fun) which were saved in my events table as type_of_event
Right now I'm fetching events only with start_at and end_at using below code:
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
Is there any specific way to show events color according to their event_type means if event type is school it will show me red color
Are you going to use these colors somewhere else outside of your model?
Most likely, you need not to make it globally available, so just add a constant to the model:
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]
来源:https://stackoverflow.com/questions/11790704/jquery-fullcalendar-change-event-color-according-to-even-type-in-ruby-app