几天来,我一直在思考 fulLCalendar、jQuery on Rails 3.2.8 的可能性。
我使用 as_json, url 来访问 model/ActiveRecords 中的记录,如下图所示:
class ZigzagPlan < ActiveRecord::Base
belongs_to :user
has_many :calories_journals
attr_accessor :no_of_cycles
attr_accessible :zz_type_used, :normal_mn_ratio_used, :start_date, :no_of_cycles
# 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.zz_type_used,
:start => self.start_date.rfc822,
:end => self.end_date.rfc822,
:allDay => true,
:url => Rails.application.routes.url_helpers.zigzag_plan_path(id), ****
:color => 'darkGrey',
textColor: 'white'
}
end
end
我很好奇是否可以在 url 上设置 DELETE 方法,因为我正在尝试开发一个删除功能,该功能不仅会删除日历上的事件,还会在 javascript/coffeescript 对话框确认框后从数据库或活动记录中删除事件。
$(document).ready ->
$('#calendar').fullCalendar
header:
left: '',
center: 'title',
right: 'prev,next today',
eventSources: [{
url: '/zigzag_plans'
},
{
url: '/calories_journals'
}],
eventClick: (calEvent, jsEvent, view) ->
alert "Deleting!" if confirm "Delete '#{calEvent.title} Journals from: #{calEvent.start} to: #{calEvent.end}' - Are you sure?" if not calEvent.title.match(/(Low|High) Day/)
removeEvent(calEvent.id) if not calEvent.title.match(/(Low|High) Day/)
removeEvent = (calEvent_id) -> $('#calendar').fullCalendar("removeEvents", calEvent_id)