我正在使用Arshaw fullcalendar。选择时间后,会提示输入姓名和电子邮件。我想将这些保存到变量和POST到我的数据库。 这是我的代码,但是当我尝试POST它时,我得到'ReferenceError:未定义电子邮件'。我究竟做错了什么?我该如何定义电子邮件?
$(document).ready ->
calendar = $("#calendar")
calendar.fullCalendar
header: (left: 'title', center: '', right: 'today prev, next, agendaWeek, agendaDay')
events:
url: 'https://www.google.com/calendar/mycalendarfeeds/'
selectable: true
selectHelper: true
select: (start, end) ->
name = prompt("Name:")
email = prompt("Email:")
if name && email
calendar.fullCalendar "renderEvent",
title: name
start: start
end: end
true
calendar.fullCalendar "unselect"
$.ajax '/events',
type: "POST"
data: event: { name: name, email: email, start: start, end: end }
success: () -> console.log("SUCCESS")
dataType: "json"
calendar_controller.rb
require 'google_calendar'
class CalendarController < ApplicationController
def index
@events = calendar.events
end
def create
event_params = params[:event]
@event = calendar.create_event do |e|
e.name = event_params[:name]
e.email = event_params[:email]
e.start = Time.parse( event_params[:start] )
e.end = Time.parse( event_params[:end] )
end
respond_to do |format|
if @event.save
format.html { redirect_to root_path, notice: "Reservation saved" }
format.json { render json: @event, status: :created, location: @event }
else
format.html {
flash.now[:notice]= "Not able to make the reservation"
render :create
}
format.json { render json: @event.errors, status: :unprocessable_entity }
end
end
end
答案 0 :(得分:0)
在确定的时刻,此变量不会收到信息或收到其他类型。