문제

I'm using gem 'httparty' on my Rails 4 app and I'm a bit confused on the actual location and syntax of where to put the the lines of code that I've been reading. As of right now, it's in my controller and I'm trying to call it through the view which is connected to my controller via routes. Here is my controller below.

require 'httparty'

class StuffsController < ApplicationController

  def index 
    count = JSON.parse(url = 'https://www.linkedin.com/countserv/count/share?url=' + url + '&format=json'
    count = JSON.parse(HTTParty.get(url).body)["count"] 
  end
end

I read this documentation from http://www.techhoppers.com/blog/ruby-on-rails/how-to-parse-the-json-api-call-with-httpparty-in-ruby-on-rails/#comment-7 and I would like to know where I'm supposed to put these two lines of code.

 response = HTTParty.get("http://example.com/call/httparty")
parsed_response = JSON.parse(response.body)

Any help would be appreciated.

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top