2013-08-28 150 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