【问题标题】:filter dropdown appear as object in Active Admin in rails 5过滤器下拉列表在 Rails 5 中的 Active Admin 中显示为对象
【发布时间】:2020-07-04 07:06:12
【问题描述】:
ActiveAdmin.register Type do
    permit_params :name, :job, version_ids: []
    index do
        id_column
        column :name
        column :job
        column :versions do |type|
            type.versions.collect(&:name).join(', ')
        end
        actions
    end

    form(html: { multipart: true }) do |f|
        f.inputs do
        f.input :name, as: :string
        f.input :job, as: :string
        f.input :versions, as: :select, input_html: { multiple: true }
        end
        f.actions
    end
end

该表与workers 表有has_many 关系。显示工作人员过滤器的下拉列表显示工作人员对象而不是工作人员名称。如何在下拉列表中获取工作人员名称而不是工作人员对象。

【问题讨论】:

    标签: ruby-on-rails ruby activerecord ruby-on-rails-5 activeadmin


    【解决方案1】:

    试试:

    f.input :versions, as: :select,
            collection: versions.pluck(:name, :id),
            input_html: { multiple: true }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-18
      • 2020-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多