ruby - Rails Display Current Facebook Share Count -


so i'm trying display current facebook share count in rails application. keep getting "can't convert string text" error when trying grab current url in rails app.

the code works if put in facebook_shares("http://www.google.com") code not work if use facebook_shares("#{request.protocol}#{request.host_with_port}#{request.fullpath}")

not sure how fix problem

here current code...

helper.rb:

def facebook_shares(url)     data = net::http.get(uri.parse("http://graph.facebook.com/?ids=#{uri.escape(url)}"))     data = json.parse(data)     data[url]['shares'] end 

view.html.erb:

<% current_url = "#{request.protocol}#{request.host_with_port}#{request.fullpath}" %> <%= facebook_shares(current_url) %> 

when run "can't convert string integer" error. works if code below:

<% current_url = "http://www.google.com" %> <%= facebook_shares(current_url) %> 

super lost...

data[url]['shares'] part suspicious. eithere data[url] gives array , when trying ['shares'] on array getting error,which obvious. or data array of something... data[url] throws error. inspect first how data looks like. error coming array#[] don't allow string inside []. see below demo code:

arr = [1,2] arr['foo'] # ~> -:2:in `[]': no implicit conversion of string integer (typeerror) # ~>  -:2:in `<main>' 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -