几天
来我一直在思考 fulLCalendar 的可能性,jQuery on Rails 3.2.8。
我使用 as_json, url 访问模型/活动记录中的记录,如下所示:
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)
使用 jquery 发送删除请求
$.ajax({
url: "/path/to/resource",
type: "POST",
data: { _method:'DELETE' },
success: function(msg) {
// do something with result
}
});