这是我的模型:
class User < ActiveRecord::Base
has_many :appointments
has_many :doctors, :through => :appointments
end
class Doctor < ActiveRecord::Base
has_many :appointments
has_many :users, :through => :appointments
end
class Appointment < ActiveRecord::Base
belongs_to :doctor
belongs_to :user
end
调用控制器动作的代码:
$.ajax({
type: "POST",
url: "/create",
data: {
appointment_date: date,
doctor_id: "1",
user_id: "1"
}
// ETC。 });
行动:
def create
@appointment = Appointment.new(:appointment_date => params[:data][:appointment_date],
:hairdresser_id => params[:data][:doctor_id], :user_id => params[:data][:user_id])
if @appointment.save
flash[:success] = "Welcome!"
redirect_to @user
else
alert("failure!")
end
end
我得到了这个错误:
NoMethodError (undefined method `[]' for nil:NilClass)
我正在使用 FullCalendar 插件,它以这种格式获取日期:
Fri Sep 13 2013 12:00:50 GMT-0400 (EDT)
我将该日期保存到日期时间字段中的数据库中。
有任何想法吗?