如何将单独的rails模型添加到active_admin表单中?

时间:2016-10-04 22:10:12

标签: ruby-on-rails ruby ruby-on-rails-4 activeadmin

我有一个ProspectReview的active_admin表单,如下所示:

ActiveAdmin.register ProspectReview do

  permit_params :domain, :media_type, :is_prospect, :category, :corrected_domain, :source, :share, :collection, :api_lookup_at

  form do |f|
    f.inputs "ProspectReview" do
      f.input :domain
      f.input :media_type, :as => :select, :collection => ["website","facebook","twitter","blogspot","tumblr","instagram","klout","pinterest","google+","linkedin","youtube","blog","mobile app","lookbook","bloglovin"]
      f.input :is_prospect, :as => :select, :collection => ["yes", "no"]
      f.input :category, :as => :select, :collection => []
      f.input :corrected_domain
      f.input :source
      f.input :share
    end
    f.actions
  end

end

我有一个名为main_topics的表,其属性名称为:

create_table "main_topics", force: :cascade do |t|
  t.string   "name", limit: 255
  t.datetime "created_at", null: false
  t.datetime "updated_at", null: false
end

我的目标是将 main_topics 中的属性名称添加到 ProspectReview ActivAdmin 表单中,其中类别选择下拉列表是:

f.input :category, :as => :select, :collection => []

只要用新行更新表 main_topics ,就会这样。无论名称列中的内容是什么,都会填充在下拉列表中。

1 个答案:

答案 0 :(得分:0)

答案很简单。

我收到错误
f.input :category, :as => :select, :collection => [MainTopic.all]

我需要删除MainTopic.all周围的[]。