2016-09-06 51 views
2

我有我認爲是一個非常簡單的應用程序,Rails 5(僅API),但由於某種原因,它返回空響應,而它應該返回一個json對象(使用RABL )Rails api-only忽略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模板是空白的...任何想法?

+0

實際上,對於**在'render'之後鍵入的所有**返回空白(儘管狀態處理完美)。嘗試'渲染'練習/索引','渲染'索引'。 –

+0

還嘗試重命名'rabl'文件帶和不帶'.json' –

+0

是否有任何其他視圖註冊了該操作,例如: 'index.html.erb'?渲染文本的輸出是什麼:@excercies.inspect'? –

回答

0

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