2013-03-09 41 views
0

我的新評論模型在網站上運行良好,但activeadmin存在問題,因爲當我轉到我的管理視圖並嘗試查看「指導」(另一個模型)時,我得到錯誤信息:引發activeadmin查看問題的新評論模型

未定義的方法`評論」的

我的模型comment.rb:

belongs_to :guideline 
belongs_to :commenter, class_name: 'User' 
attr_accessible :body, :commenter_id 

我的模型guideline.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 

管理/ guidelines.rb:

index do        
    column :comment  
    default_actions     
end 
+0

'未定義方法'評論' - 是整個錯誤信息? – 2013-03-09 12:49:35

回答

0

你得到一個未定義的方法錯誤,因爲你的指南模型的has_many意見,因此具有方法.comments但不.comment 。如果您試圖顯示指南的評論數量,那麼您可以執行此操作。

column "Comments" do |guideline| 
    guideline.comments.count 
end 

如果你想顯示所有羅列出來,你可以收集無論列是保存文本註釋對象,並用逗號或換行等

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

加入他們的實際意見HERE是關於如何定製ActiveAdmin索引表的更多信息。