简体   繁体   中英

Rendering HTML instead of JSON: Ruby on Rails

I have an API that I am trying to call from a method within my application. 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.

This is the method in the controller:

def index
  @moviedetails = Moviedetail.all
  respond_to :json
end

This is the API call from the method

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中返回的

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM