2013-04-21 61 views
0

我使用所謂的 acts_as_commentable_with_threadinghttps://github.com/elight/acts_as_commentable_with_threading)寶石和acts_as_followerhttps://github.com/tcocca/acts_as_follower我如何獲取我的關注的所有評論?

到目前爲止,一切工作正常。我所有的追隨者和追隨者都沒有問題。

現在,我正在嘗試獲取所有以下用戶的所有評論。 所以我試過

@users = current_user.following_users 
@comments = @users.comment_threads.order("updated_at DESC").page(params[:page]).per(10) 

但是,它返回這個錯誤。

NoMethodError (undefined method `comment_threads' for #<ActiveRecord::Relation:0x0000000d1b7a58>): 

爲什麼以及如何解決這個問題? acts_as_commentable_with_threading不支持數組對象?

回答

1

基礎上code,你可能會需要這樣的東西,如:

user_ids = current_user.following_users.map(&:id) 
commentable = User.base_class.name.to_s 
@comments = Comment.where(:user_id => user_ids, :commentable_type => commentable).order('created_at DESC') 

以上將得到評論的user_ids數組,而不僅僅是一個用戶

+0

感謝,但我已經得到了這個錯誤:('ActiveRecord :: StatementInvalid(Mysql2 ::錯誤:列'ID'在字段列表中是不明確的:SELECT ID FROM'用戶'INNER JOIN'後面'ON'跟隨''.'followable_id' ='用戶'.'''後跟''.''''''''''''''''''''''''''''''''''和''後面跟隨''''和'跟隨'。 'follow'.'''''''lowlow_type' ='User'AND('use rs'.'deleted_at'是NULL)): ' – cat 2013-04-21 18:33:48

+0

@cat - 更新到不會給你那個錯誤 – 2013-04-21 21:28:32

+0

非常感謝:)它的工作 – cat 2013-04-22 11:32:06

相關問題