.count as count

编程入门 行业动态 更新时间:2024-10-16 20:31:00
.count as count_all不返回变量名。(.count as count_all doesn't return the variable name.)

我有一个返回约会的方法。 但是,对于这个特定的位,我希望只返回任何给定日期的约会数量。

日志显示我检索数据,但我似乎无法显示它。 似乎我检索的数据返回时没有任何名称来访问它。

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 end

I 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_a

if you need to know how many elements are in @appointments_count you can apply size after converting it to array (.to_a)

更多推荐

本文发布于:2023-04-29 03:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1334490.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:count

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!