仅Rails API忽略Rabl文件 [英] Rails api-only ignoring rabl files

查看:81
本文介绍了仅Rails API忽略Rabl文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信我的应用程序非常简单,使用Rails 5(仅API),但由于某种原因,它返回一个空响应,而应该返回一个json对象(使用RABL)

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

如果我使用直接渲染(注释),它可以正常工作,但是使用rabl模板时,它是空白的...有什么想法吗?

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

推荐答案

尝试将config.view_paths = ['/app/views']添加到您的配置中.

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

这篇关于仅Rails API忽略Rabl文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆