Ruby on rails 导致activeadmin视图问题的新注释模型

Ruby on rails 导致activeadmin视图问题的新注释模型,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我的新评论模型在网站上运行良好,但activeadmin存在一个问题,因为当我转到我的管理视图并尝试查看“指南”(另一个模型)时,我会收到一条错误消息: 未定义的方法“comment” My model comment.rb: belongs_to :guideline belongs_to :commenter, class_name: 'User' attr_accessible :body, :commenter_id My model Guide.rb: attr_accessible

我的新评论模型在网站上运行良好,但activeadmin存在一个问题,因为当我转到我的管理视图并尝试查看“指南”(另一个模型)时,我会收到一条错误消息:

未定义的方法“comment”

My model comment.rb:

belongs_to :guideline
belongs_to :commenter, class_name: 'User'
attr_accessible :body, :commenter_id
My model Guide.rb:

attr_accessible :content, :hospital, :title, :user_id, :guideline_id, :specialty, :updated_by, :current_user, :subtitle, :slug, :activities, :comment, :visible
belongs_to :user
has_many :favourite_guidelines
has_many :comments, :dependent => :destroy
admin/guidelines.rb:

index do                              
  column :comment     
  default_actions                   
end

您得到一个未定义的方法错误,因为您的指南模型有许多注释,因此有方法
.comments
,但没有
.comment
。如果您试图显示一个指南的评论数量,那么您可以这样做

column "Comments" do |guideline|
  guideline.comments.count
end
如果要显示列出的所有实际注释,可以收集包含文本的注释对象中的任何列,并用逗号或换行符等将它们连接起来

column "Comments" do |guideline|
  guideline.comments.collect(&:text_form_of_comment).join(",")
end

是有关如何自定义ActiveAdmin索引表的详细信息。

的未定义方法“comment”
——这就是整个错误消息吗?