I think the problem is actually your controller, not your view.
JSON.parse(response)
should be
JSON.parse(@response)
You probably want in your view:
<%= @response.body %>
문제
I am trying to get a response from the movie db using its default response, using the movies id http://docs.themoviedb.apiary.io/. Haven’t done this before so lots of mistakes im sure.
So I'm using the gems httparty and json and have setup everything like so
controller
require 'httparty'
require 'json'
class MainController < ApplicationController
def index
@response = HTTParty.get("http://api.themoviedb.org/3/movie/550?api_key="api_key")
JSON.parse(response)
end
end
and my view
<%= @response %>
just wanted to see what was returned.
I get the error can't convert ActionDispatch::Response into String
I was wondering if someone could offer some advice or some resources to look at to learn how do do this, and maybe some different methods to display the info returned.
I know that a hash is a collection of key/values but lack the knowledge to extract that data
Thank you
해결책
I think the problem is actually your controller, not your view.
JSON.parse(response)
should be
JSON.parse(@response)
You probably want in your view:
<%= @response.body %>