【问题标题】:Generating charts with only users patients, not entire patient db. Ruby on rails生成仅包含用户患者的图表,而不是整个患者数据库。轨道上的红宝石
【发布时间】: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 ?

标签: ruby-on-rails chartkick


【解决方案1】:

简单使用

current_user.patients.group(:ailment).count

【讨论】:

  • 太棒了。非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-24
  • 1970-01-01
  • 2022-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多