1

我正在尝试使用 jbuilder 在我的 rails 应用程序中渲染一些 json,但输出显示为:

{"status":"500","error":"Internal Server Error"}

这是网址:

http://localhost:3000/api/v1/appusers/10

这是控制器:

module Api
  module V1
    class AppusersController < ApplicationController
      respond_to :json
      skip_before_action :verify_authenticity_token

      def show
        @appuser = Appuser.find(params[:id])      
      end

还有我的 show.json.jbuilder 文件:

json.extract! @appuser, :user_auth_token, :id
end

我以前从未在使用 jbuilder 时遇到过这种情况,我所有的其他 jbuilder 文件都可以正常工作。知道我错过了什么吗?

4

1 回答 1

2

根据文档,您不需要模板end中的,只需:jbuilder

json.extract! @appuser, :user_auth_token, :id

或者,如果您使用的Ruby版本高于 1.9,则可以使用以下语法:

json.(@appuser, :user_auth_token, :id)
于 2014-03-16T19:29:36.497 回答