Alright, Iv'e done some research but still no luck...
I'll explain what I'm trying to do first:
I have an app which is sign in through Facebook only. I would like these users to see a list of their friends that are using my application as well.
I have routed users#index
to return a list of users friends that are currently on the application. This is displayed in JSON Data
. This data is returned as follows: "name"=>"Example Name", "id"=>"32938293828393"
. In my database, I store all users Facebook uid's
. I'd now like to be able to find a user by matching the returned JSON id
, by matching it with the uid
that iv'e stored in the database.
This is my current users_controller.rb
:
def index
@users = current_user.facebook.get_connections("me", "friends")
@value = '{"id":"name"}'
json = JSON.parse(@value).with_indifferent_access
@users.find(params[json[:id] == :uid])
end
and this is my index.html.erb
:
<%= @users.each do |user| %>
<%= link_to user.first_name, user %>
<% end %>
Iv'e been trying to do this for the past day with no luck... Done a lot of research. If there is a resource online explaining how to handle this, please drop a link below. Any help is greatly appreciated. Thanks :)
Found a solution! Will post an answer for anyone else who may need help in the future with a similar problem..
In my users_controller.rb
I now have
class UsersController < ApplicationController
def index
@friends = current_user.facebook.get_connections("me", "friends")
uids = @friends.collect { |f| f["id"] }
registered_friends = User.where('uid IN (?)', uids)
@pals = registered_friends
end
end
And now in my Users/index.html.erb
I now have
<% @pals.each do |pal| %>
<%= link_to pal.first_name, wall_path(pal.id) %>
<% end %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.