How to use ActiveAdmin on models using has_many through association?

前端 未结 6 1274
南笙
南笙 2020-12-12 11:28

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

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 12:08

    If you would like show multiple field in a panel row you can use following view:

    show do |phy|
       panel "Details" do
            attributes_table do
              ... # Other fields come here
              row :appointment_dates do
                apps=""
                phy.appointments.all.each do |app|
                  apps += app.patient.name + ":" + app.appoinment_date + ", "
                end
                apps.chomp(", ")
              end
            end      
       end
    end
    

    To place it in you redit form first put appointment_ids to permitted list:

    permit_params: appointment_ids:[]
    

    Add has many relationship to the form

    form do |f|
       f.has_many :appointments do |app|
         app.inputs "Appointments" do
           app.input :patients, :as => :select, :label => "Assigned Patients"
           app.input :appointment_date
         end  
       end
    end
    

    Should work if there is no coding error.

提交回复
热议问题