[英]Rendering HTML instead of JSON: Ruby on Rails
I have an API that I am trying to call from a method within my application. 我有一个API,正在尝试从应用程序中的方法调用。 Even though I am calling the API using the json format, and I am setting the respond_to to JSON, it still renders as HTML.
即使我使用json格式调用API,并且将response_to设置为JSON,它仍然呈现为HTML。
This is the method in the controller: 这是控制器中的方法:
def index
@moviedetails = Moviedetail.all
respond_to :json
end
This is the API call from the method 这是来自方法的API调用
def self.searchHighestRating()
url="https://ruby-rsudding.c9users.io/moviedetails.json"
response = HTTParty.get(url)
responsebody = JSON.parse(response.body)
return responsebody
end
Any thoughts around how I could resolve this? 关于如何解决这个问题有任何想法吗?
将render json:放入并确保答案实际上是在json中返回的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.