Rails 活动管理员复选框不显示所选选项

Rails Active Admin checkboxes not displaying selected options

我有两个模型有 has_and_belongs_to_many 关系

class ArticleRejectionReason < ActiveRecord::Base

attr_accessible :reason 
has_and_belongs_to_many :articles
end

class Article < ActiveRecord::Base
has_and_belongs_to_many :article_rejection_reasons
end


ActiveAdmin.register Article do
  permit_params article_rejection_reason_ids: []

  f.inputs "Article Details" do
   f.input :article_rejection_reasons, as: :check_boxes, collection: ArticleRejectionReason.all.collect { |r| [r.reason, r.id] }
 end
end

复选框(选项)按预期生成。我可以将数据保存到数据库中。

但是,当我点击 'edit' 按钮时,我没有看到显示所选的选项。

我知道如何在 jQuery 中执行此操作。如何在活动管理员中显示选定的选项?

更新 1:

mysql> select * from article_rejection_reasons_articles;
+------------+-----------------------------+
| article_id | article_rejection_reason_id |
+------------+-----------------------------+
|        386 |                           2 |
|        386 |                           4 |
|        386 |                           6 |
+------------+-----------------------------+

更新 2:

根据rails命名约定,'has_and_belongs_to_many'应该有复数关联。

class ArticleRejectionReason < ActiveRecord::Base

attr_accessible :reason 
has_and_belongs_to_many :articles /* plural */
end

class Article < ActiveRecord::Base
has_and_belongs_to_many :article_rejection_reasons /* plural */
end


ActiveAdmin.register Article do
  permit_params article_rejection_reason_ids: []
  form do |f|
  f.inputs "Article Details" do
   f.input :article_rejection_reasons, as: :check_boxes, collection: ArticleRejectionReason.all.collect { |r| [r.reason, r.id] }
  end
 end
end

This link may be helpful to you.