I created an rails api to expose my Bottl class. This class has some methods for solving the 99Bottles problem. The song method, for instance, returns the complete lyrics song. My intention is to return a JSON, according to JSON API containing the response of that method.
require_relative '../bottles_logic/bottles'
class SongsController < ApplicationController
before_action :set_song, only: [:show, :update, :destroy]
# GET /songs
def index
@songs = ::Bottl.new.song
render json: @songs
end
end
Using Postman, I get 200 status and the request payload, however, JSON is not shown due to syntax error (unexpected 'S').
My questions are:
- How to return a JSON according to the JSON API in this case?
- Do I need to use a Serializer to format this JSON?
- I'd like to return the lyrics in a json entry called whole_song, so it must be an attribute, right?
syntax error (unexpected 'S')and the lines right after?