Rails iterate over objects array -


i want this

@groups = community::groupmember.where(:member_id => current_user.id)       user_ids = []       @groups.each |group|         user_ids << @group.community_group_members.where(:group_id =>    group.id).pluck(:member_id)       end 

but error nomethoderror - undefined method `community_group_members' think im not iterating @groups way want.

you should have:

user_ids << group.community_group_members.pluck(:member_id) 

(group instead of @group). it's because inside each block, element of array represented local variable (which unprefixed) instead of instance variable (prefixed @). @group instance variable unset , evaluated nil, doesn't respond community_group_members method.

also, deleted where clause, since it's reduntant - you're doing in group.community_group_members call.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -