ActiveAdmin嵌套表单在#show页面上

是否可以将嵌套表单添加到#show页面?

现在我有我的admin / posts.rb:

ActiveAdmin.register Post do show do |post| h2 post.title post.comments.each do |comment| row :comment do comment.text end end end end 

它列出了post的所有评论。 现在我需要一个表单来添加新评论。 我想这样做:

 ActiveAdmin.register Post do show do |post| h2 post.title post.comments.each do |comment| row :comment do comment.text end end form do |f| f.has_many :comments do |c| c.input :text end end end end 

并得到一个错误:

的未定义方法`has_many’:Arbre :: HTML :: Form

post和评论的模型如下:

 class Post < ActiveRecord::Base has_many :comments accepts_nested_attributes_for :comments end class Comment < ActiveRecord::Base belongs_to :post end 

如何将该表单添加到我的显示页面? 谢谢

将此类信息添加到节目页面时,我使用以下方法

  ActiveAdmin.register Post do show :title => :email do |post| attributes_table do row :id row :first_name row :last_name end div :class => "panel" do h3 "Comments" if post.comments and post.comments.count > 0 div :class => "panel_contents" do div :class => "attributes_table" do table do tr do th do "Comment Text" end end tbody do post.comments.each do |comment| tr do td do comment.text end end end end end end end else h3 "No comments available" end end end end 

我为has_one关系做了类似的事情:

 ActiveAdmin.register Post do show :title => :email do |post| attributes_table do rows :id, :first_name, :last_name end panel 'Comments' do attributes_table_for post.comment do rows :text, :author, :date end end end end 

如果你不需要增加sorens解决方案的灵活性,我打赌你可以使用它。