Closed ambethoney closed 9 years ago
I don't see an error message printed out above.
I just check your server.rb
file and there seem to be a few errors there
@all_contacts = @contacts.lrange "contacts_list#{@name}", 0, -1
What is @contacts
? You're calling lrange
on it, which is a method from redis.
I also don't see in your code where you create the contacts_listNAME. You're doing an lrange but when do you push contact names into the list?
I've just committed my new work. I'm still working on the same thing (trying to list out my contacts list), but I'm much further along than before. At this point, I'm receiving this error:
TypeError - no implicit conversion of String into Integer:
/Users/ambethoney/dev/network.ly/databasehelper.rb:27:in `[]'
/Users/ambethoney/dev/network.ly/databasehelper.rb:27:in `get_contact_info'
In Pry, when I try to extract my contacts list from the contact_info hash like this:
contact_info["values"][1]["firstName"]
"Katie"
it works. However, in my DatabaseHelper, I'm unsure as to how to get the contact#{id} information. I have this set up in my server: (sorry about the indentation..)
get '/home' do
ids = $redis.lrange("contacts_list", 0, -1)
@my_contacts = ids.map {|id| $redis.hgetall("user:#{id}")}
render :erb, :home, layout: :default
end
post('/home') do
id = $redis.incr("every_contact")
$redis.hmset("contact:#{id}",
"f_name", params["f_name"],
"l_name", params["l_name"],
)
$redis.lpush("contacts_list", id)
redirect to '/home'
end
This assigns each contact an id number, but whenever I try to make id an instance variable so I can call it in DatabaseHelper, I receive even more errors. I'm confused about how to work around this.
I just updated your comment. Make sure when you paste in code blocks that you surround them with three back ticks ```
Oh okay
I'm closing this issue for now as the main problem of accessing the values from the JSON response as an array rather than a hash has been solved.
Hi Phil,
I'm getting some errors whenever I try to create a list of contacts obtained from the LinkedIn API. The error I'm currently receiving is /
/
I understand what this error means, I'm just having a hard time trying to figure out how to get the contacts to print out! I've tried using an lrange method and an each do method, but I keep receiving a nil error. I'm not sure why my code is unable to retrieve this information. Help!