【发布时间】:2018-04-02 14:23:22
【问题描述】:
我正在使用 ChartKicks 在 Rails 中创建图表。目前,图表是通过使用数据库中的every 来生成的。我怎样才能让这只是当前用户的患者。我正在使用清除宝石,所以是当前用户。
呈现报告页面的控制器
def report
render 'patients/report'
end
def create
@patient = current_user.patients.build(patient_params)
if @patient.save
redirect_to patient_path(@patient), notice: "Patient Added"
else
@errors = @patient.errors.full_messages
render :new
end
end
生成报告的页面
<div class="row charts">
<div class="col-md-6" id="patients-illness">
<%= pie_chart Patient.group(:ailment).count %>
</div>
</div>
【问题讨论】:
-
为什么使用 Patient.group(:ailment).count,为什么不使用 current_user.patients.group(:ailment).count ?