我有一个返回约会的方法。 但是,对于这个特定的位,我希望只返回任何给定日期的约会数量。
日志显示我检索数据,但我似乎无法显示它。 似乎我检索的数据返回时没有任何名称来访问它。
NoMethodError([“2014-03-29”,2]的未定义方法`date_startdate':数组)
即使SQL语句说:
SELECT COUNT(*)AS count_all,DATE(startDate)AS date_startdate FROM“appointmentments”WHERE(garage =='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 endI have a method which returns appointments. However, for this particular bit I'm looking to return only the number of appointments for any given day.
The logs show that I retrieve the data, but I seem unable to display it. It seems that the data I retrieve gets returned without any name to access it.
NoMethodError (undefined method `date_startdate' for ["2014-03-29", 2]:Array)
even though the SQL statement says:
SELECT COUNT(*) AS count_all, DATE(startDate) AS date_startdate FROM "appointments" WHERE (garage == 't') GROUP BY DATE(startDate)
Here is my method
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最满意答案
删除count ,因为分组后的计数返回{value_of_grouped_field => count}
@appointments_count = Appointment.where("garage == ?", true).group("DATE(startDate)").to_a如果您需要知道@appointments_count有多少元素,您可以在将其转换为数组后应用size ( .to_a )
Remove count, because count after grouping returns object like {value_of_grouped_field => count}
@appointments_count = Appointment.where("garage == ?", true).group("DATE(startDate)").to_aif you need to know how many elements are in @appointments_count you can apply size after converting it to array (.to_a)
更多推荐
发布评论