【问题标题】:Ransack sort link for has many associationRansack 排序链接有很多关联
【发布时间】:2016-01-22 04:40:48
【问题描述】:

Rails 4.2.4、Ruby 2.2.3、Ransack 1.7.0

我有一个模型:

class Patient < ActiveRecord::Base
  has_many :patient_statuses

   def latest_status
     self.patient_statuses.last.status
   end
end

另一个模型为:

class PatientStatus < ActiveRecord::Base
  belongs_to :patient

  enum status: [:registered, :pending, :check_up, :admitted, :discharged]
end

我有PatientsController#index 操作

def index
    @query = Patient.ransack(params[:q])
    @patients = @query.result
end

如何按latest_status 对患者进行分类?

喜欢

sort_link @query, :package_latest_status, 'Status' # index.html.erb

【问题讨论】:

    标签: ruby-on-rails associations has-many ransack


    【解决方案1】:

    不确定它是否有效,但您尝试过吗?

    Model.status.find_each
    

    例如

    Patient.registered.find_each
    Patient.pending.find_each
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-17
      • 2017-05-30
      • 1970-01-01
      • 2019-02-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      相关资源
      最近更新 更多