passing values from controller to partial

Hii How can i pass array of values from the controller to partial.

def dispfriends @myfriend= @myfriendlogin = @myusers=

i=0 @currentgroup = Group.find_by_id(params[:groupid])

puts @currentgroup.id

@currentfriends= GroupFriend.find_all_by_user_id_and_group_id(current_user.id, @currentgroup.id)

for n in @currentfriends @myfriend=n.friend_id puts @myfriend @myusers = User.find_by_id(@myfriend) @myfriendlogin[i]=@myusers.id puts @myfriendlogin[i] i=i+1

end

I can print @myfriendlogin (id, name, address) individually and show the value in the view. But,

My requirement is I need to pass complete @myusers array to my view.

Please help like how can i pass all the fields in @myusers.

Please help. thank you.

Ravi Dtv wrote:

Hii How can i pass array of values from the controller to partial.

Just like you'd pass any other variable to any other view. No difference.

def dispfriends @myfriend= @myfriendlogin = @myusers=

This is terrible controller code. To start with, the name of the method is bad.

i=0 @currentgroup = Group.find_by_id(params[:groupid])

puts @currentgroup.id

@currentfriends= GroupFriend.find_all_by_user_id_and_group_id(current_user.id, @currentgroup.id)

No! Use associations for this.

for n in @currentfriends @myfriend=n.friend_id puts @myfriend @myusers = User.find_by_id(@myfriend) @myfriendlogin[i]=@myusers.id puts @myfriendlogin[i] i=i+1

That's not how you do it in Ruby. Learn about Array methods such as each and collect.

end

I can print @myfriendlogin (id, name, address) individually and show the value in the view. But,

My requirement is I need to pass complete @myusers array to my view.

Please help like how can i pass all the fields in @myusers.

It's just a variable. Pass it like any other variable.

Please help. thank you.

Best,