undefined method `pluck' for []:Array
I'm trying to implement it in one app but I got this error msg: " undefined method `pluck' for []:Array", I think that this is in this query: "followees_ids = current_user.followees(User).pluck(:id)". I'll be grateful if anyone help me in solve this issues.
followees_ids = current_user.followees(User).pluck(:id) Looks like the current_user has not followed anyone, there should be a small check, have this method in your controller and remove that line
def followees_ids
current_user.followees(User) && current_user.followees(User).pluck(:id)
end
Hi Vysakh, thanks for the reply! I did as you mentined but the issue continues, now in the function. In the console, when I try it: current_user.followees(User) is return [].
That is because the current_user is not following anyone. When a user first signs up he/she is not following anyone, so current_user.followees(User) is empty, subsequently your news feed is empty. If you want that to return some value, you need to follow another user in your app, then the array will not be empty :)
Sorry, I'm nb. I'm trying do that....
if followees_ids
@activities = PublicActivity::Activity.where(owner_id: followees_ids, owner_type: "User")
end
...
def followees_ids current_user.followees(User) && current_user.followees(User).pluck(:id) end
But still got a msg: "undefined method `pluck' for []:Array"
How could I solve that?
Go to rails console and check these, temme what output you get
user = User.first
user.followees(User)
Also, could you push your code in github so that I could see?
It return [] in console. I think that it solve the problem... unless current_user.followees(User).empty? followees_ids = current_user.followees(User).pluck(:id) end
hai @joao32 this is very late message .. Try this if you are using Rails 4 followees_ids = current_user.followees(User).map(&:id)