内部错误500 jbuilder

问题描述:

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

I'm trying to render some json in my rails app using jbuilder, but the output is showing up as:

{"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文件:

And my show.json.jbuilder file:

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

我以前从未在jbuilder上遇到过这个问题,我所有其他jbuilder文件都可以正常工作.知道我想念的是什么吗?

I've never encountered this before with jbuilder and all of my other jbuilder files work just fine. Any idea what I'm missing?

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

According to documentation, you don't need the end in the jbuilder template, just:

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

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

Alternatively, if you are using a Ruby version major than 1.9, you can use this syntax:

json.(@appuser, :user_auth_token, :id)