我有一个返回约会的方法。但是,对于这一点,我希望只返回任何一天的约会数量。
日志显示我检索数据,但我似乎无法显示它。似乎我检索的数据返回时没有任何名称来访问它。
NoMethodError(未定义的方法`date_startdate' for [" 2014-03-29",2]:Array)
即使SQL语句说:
SELECT COUNT(*)AS count_all,DATE(startDate)AS date_startdate FROM "预约" WHERE(车库==' t')GROUP BY DATE(startDate)
这是我的方法
def get_appointment_count
@appointments_count = Appointment.where("garage == ?", true).group("DATE(startDate)").count.to_a
appointments = []
#render :text => @appointments.to_json
@appointments_count.each do |appointment|
appointments << {
:id => 1,
:title => 'Taken',
:description => 'count_all',
:start => appointment.date_startdate,
:end => appointment.date_startdate,
:allDay => true,
:editable => true
}
end
render :text => appointments.to_json
end
答案 0 :(得分:0)
删除count
,因为分组后计数会返回{value_of_grouped_field => count}
@appointments_count = Appointment.where("garage == ?", true).group("DATE(startDate)").to_a
如果您需要知道@appointments_count
中有多少元素,您可以在将其转换为数组后size
应用.to_a