2013-08-28 193 views
0
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]] 
Follow Load (0.2ms) SELECT "follows".* FROM "follows" WHERE "follows"."follower_id" = 2 AND "follows"."follower_type" = 'User' AND "follows"."blocked" = 'f' 
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" IN (1) 
Conference Load (0.1ms) SELECT "conferences".* FROM "conferences" WHERE "conferences"."id" IN (4) 
=> [#<Follow id: 8, followable_id: 1, followable_type: "User", follower_id: 2, follower_type: "User", blocked: false, created_at: "2013-08-28 06:57:17", updated_at: "2013-08-28 06:57:17">, #<Follow id: 9, followable_id: 4, followable_type: "Conference", follower_id: 2, follower_type: "User", blocked: false, created_at: "2013-08-28 07:03:35", updated_at: "2013-08-28 07:03:35">] 

這種使用條件是輸出我在控制檯中看到,當我嘗試無法在軌控制檯

User.find(2).all_follows 

我想要得到的行,其中的followable_type:「Conferece」。

我想這

User.find(2).all_follows.find(:conditions => ["followable_type = ?", "Conference"]) 

User.find(2).all_follows.where(:all, :conditions => ["followable_type = ?", "Conference"]) 

當我用在哪裏,它說沒有這樣的功能。但是,當我打字,我得到以下輸出

User.find(2).all_follows.where 
2).all_follows.where    2).all_follows.where_sql     
2).all_follows.where_values=  2).all_follows.wheres 
2).all_follows.where_clauses  2).all_follows.where_values    
2).all_follows.where_values_hash 2).all_follows.wheres= 
+0

什麼是all_follows? –

+0

它將返回用戶所關注的所有人員和會議。我正在使用這個函數,因爲我已經使用了act_as_followable gem – Aravind

+0

我可以看到,但它是一個範圍(或返回範圍的東西)或數組? –

回答

0

後按Tab鍵試試這個..

User.find(2).all_follows.select{ |user| user.followable_type == "Conference" } 
+0

這是我得到的錯誤NoMethodError:未定義的方法'其中'爲# Aravind

+0

@Aravind編輯我的答案..試試這個 –

+0

謝謝。它現在有效。 – Aravind