[英]Rails - Project.where(created_at: (Time.now - 24.hours)..Time.now) returning <Project::ActiveRecord_Relation:0x007f5470c7a378>
我想做的是統計過去24小時內發布的所有項目。
class ApplicationController < ActionController::Base
before_action :projects_today
def projects_today
@projects_today = Project.where(created_at: (Time.now - 24.hours)..Time.now)
end
end
視圖
<h1><%= @projects_today %></h1>
但是,視圖中顯示的是“ Project :: ActiveRecord_Relation:0x007f5470c7a378”,而不是所需的答案62。
您忘記添加count
:
@projects_today = Project.where(created_at: (Time.now - 24.hours)..Time.now).count
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.