Rails api-only ignoring rabl files

扶醉桌前 提交于 2019-12-10 11:22:59

问题


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:


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



来源:https://stackoverflow.com/questions/39358632/rails-api-only-ignoring-rabl-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!