2012-08-03 2 views
1

내 루비 앱에서 http://arshaw.com/fullcalendar의 Jquery 전체 캘린더를 사용하고 있습니다. 내 이벤트 테이블에 type_of_event로 저장 한 (휴일, 학교, 직장, 재미)와 같은 4 가지 종류의 이벤트에 서로 다른 색상을 표시하고 싶습니다.Jquery FullCalendar- 루비 앱의 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에 따라 이벤트 색상을 표시하는 특정 방법이 있나요은

답변

2

당신이 당신의 모델 이외의 다른 곳에서이 색상을 사용하는 건가요 의미?

대부분의 경우, 당신은 그래서 그냥 모델에 일정을 추가, 그것은 전 세계적으로 사용할 수 있도록 할 필요가 없습니다 :

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] 
관련 문제