Hell All,
I am using a ruby gem called socialization (https://github.com/cmer/socialization)
I have it working and I am able to follow and unfollow a user and see how many people are following or followed by any user. the issue is when I want to output the usernames of the followers and following, it only works for user1, and for user 2-4 it will show the usernames in order based on how many followers e.g. if the table is
- user1 follows => user 2
- user2 follows => user 3
and I ask for the followers for user 3 (knowing user3 as 1 follower) it will print out User1 regardless (i hope this makes sense)
Here is my code:
Followers method in UsersController
def followers
@user = User.find(params[:user])
@followers = @user.followers(User)
@users = User.all
response = {:user => @user, :followers => @followers, :users => @users}
respond_to do |format|
format.html #followers.html.erb
format.xml {render :xml => response}
end
end
Following method in UsersController
def following
@user = User.find(params[:user])
@following = @user.followers(User)
@users = User.all
response = {:user => @user, :following => @following, :users => @users}
respond_to do |format|
format.html #following.html.erb
format.xml {render :xml => response}
end
end
following View:
<p><u>Following</u></p>
<% (1..(@following.count)).each do |i| %>
<% if @users[i].followed_by?(@user) %>
<p> <%= @users[i].username %> </p>
<% end %>
<% end %>
Followers view
<p><u>Followers</u></p>
<% (1..(@followers.count)).each do |i| %>
<% if @users[i].follows?(@user) %>
<p> <%= @users[i].username %> </p>
<% end %>
<% end %>
My route
resources :users do
match 'show/:id' => 'user#show'
collection do
get 'follow'
get 'unfollow'
get 'followers'
get 'following'
end
the only one that seems to work correctly is /users/followers?user=1
everything else either shows nothing or the wrong names.
Any help would be appreciated!