簡體   English   中英

僅Rails API忽略Rabl文件

[英]Rails api-only ignoring rabl files

我相信我是一個非常簡單的應用程序,帶有Rails 5(僅API),但由於某種原因,它正在返回一個空響應,而它應該返回一個json對象(使用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模板時,它為空白...有什么想法嗎?

嘗試將config.view_paths = ['/app/views']到您的配置中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM