2014-10-27 69 views
0

我想一些日誌時出現錯誤:麻煩記錄器

NoMethodError in RelationController#create 
undefined method `attributes' for #<ActiveRecord::Relation:0x431e650> 

這是我的控制器

def create 
    follow = User.find(params[:relation][:following_id]) 
    current_user.following << follow 
    logger.debug "follow: #{follow.attributes.inspect}" 
    logger.debug "current_user: #{current_user.attributes.values}" 
    logger.debug "following: #{current_user.following.attributes.values}" 
    redirect_to follow 
    end 

我能做些什麼來解決這個問題,請大家幫幫我!

回答

0

你錯誤的原因是該行

logger.debug "following: #{current_user.following.attributes.values}" 

你打電話attributescurrent_user.following這是一個ActiveRecord::Relation對象。如果你想登錄,您可以通過每個current_user.following必須循環並在其上

current_user.following.each do |follow| 
    logger.debug "following: #{follow.attributes.values}" 
end 
+0

它工作呼叫attributes!謝謝 :) – mayoneQD 2014-10-27 07:26:55