2
votes

I have what I believe to be a very simple app, with Rails 5 (API only) but for some reason it is returning an empty response while it should be returning a json object (using RABL)

class ExercisesController < ApplicationController
  before_action :set_exercise, only: [:show, :update, :destroy]

  def index
    @exercises = Exercise.all

    # Works
    # render json: @exercises

    # Blank response
    render :index
  end
end

# app/views/exercises/index.json.rabl
collection @exercises
attributes :id, :name

If I use a direct render (commented) it works properly, but with the rabl template it is blank... any thoughts?

1
in fact, it returns blank for whatever is typed after render (though statuses are processed perfectly). Tried render 'exercises/index', render 'index'. - Saravanabalagi Ramachandran
Also tried renaming the rabl file with and without .json - Saravanabalagi Ramachandran
Is there any other view registered for that action, e.g. index.html.erb? What is the output of render text: @excercies.inspect ? - phil pirozhkov
Seems Rabl doesn't support Rails 5 yet, unfortunately. - Lenin Raj Rajasekaran
I think the issue is also related to the libraries loaded. Have you loaded Rabl? Because the --api flag limits the amount of libraries that Rails loads, and may not have rendering setup in such a way that Rabl hooks into it properly. - ekampp

1 Answers

0
votes

Try adding config.view_paths = ['/app/views'] to your configuration.