如何通过关联在使用 has_many 的模型上使用 ActiveAdmin? [英] How to use ActiveAdmin on models using has_many through association?

查看:23
本文介绍了如何通过关联在使用 has_many 的模型上使用 ActiveAdmin?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用
(来源:rubyonrails.org)

我如何使用 ActiveAdmin 来...

  1. 在医生页面显示每位患者的预约日期?
  2. 在医生页面编辑每位患者的预约日期?

谢谢大家.:)

解决方案

对于 1)

show do小组患者"做table_forphysician.appointments 做列姓名"做|约会|预约.病人.姓名结尾列:约会日期结尾结尾结尾

对于 2)

form do |f|f.inputs "Details" do # 医生的字段f.输入:名称结尾f.has_many :约会做|app_f|app_f.inputs "约会" 做如果 !app_f.object.nil?# 仅当它是现有约会时才显示销毁复选框# 否则,已经有动态 JS 来添加/删除新约会app_f.input :_destroy, :as =>:boolean, :label =>破坏?"结尾app_f.input :patient # 它应该自动生成一个下拉选择以从您现有的患者中进行选择app_f.input :appointment_date结尾结尾结尾

I am using ActiveAdmin gem in my project.

I have 2 models using has_many through association. The database schema looks exactly the same as the example in RailsGuide. http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association
(source: rubyonrails.org)

How can I use ActiveAdmin to ...

  1. show appointment date of each patient in physicians page?
  2. edit appointment date of each patient in physicians page?

Thanks all. :)

解决方案

For 1)

show do
  panel "Patients" do
    table_for physician.appointments do
      column "name" do |appointment|
        appointment.patient.name
      end
      column :appointment_date
    end
  end
end

For 2)

form do |f|
  f.inputs "Details" do # physician's fields
    f.input :name
  end

  f.has_many :appointments do |app_f|
    app_f.inputs "Appointments" do
      if !app_f.object.nil?
        # show the destroy checkbox only if it is an existing appointment
        # else, there's already dynamic JS to add / remove new appointments
        app_f.input :_destroy, :as => :boolean, :label => "Destroy?"
      end

      app_f.input :patient # it should automatically generate a drop-down select to choose from your existing patients
      app_f.input :appointment_date
    end
  end
end

这篇关于如何通过关联在使用 has_many 的模型上使用 ActiveAdmin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆