【问题标题】:Internal Error 500 jbuilder内部错误 500 jbuilder
【发布时间】:2014-04-21 21:40:10
【问题描述】:

我正在尝试使用 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 文件都可以正常工作。知道我错过了什么吗?

【问题讨论】:

    标签: ruby-on-rails json jbuilder


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 我曾尝试关闭末端(但这引发了错误)。不过,使用这种新语法就像魅力一样!
    猜你喜欢
    • 2017-07-04
    • 2015-11-24
    • 2017-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-25
    • 2012-04-25
    相关资源
    最近更新 更多