1

我正在使用 Arshaw fullcalendar。选择时间后,它会提示输入姓名和电子邮件。我想将这些保存到变量中并 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"

日历控制器.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
4

1 回答 1

0

在确定的时刻,这个变量不会接收到信息或接收到不同的类型。

于 2013-10-18T13:03:44.333 回答