質問

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"}

Here's the url:

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

Here's the controller:

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

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

And my show.json.jbuilder file:

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

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

役に立ちましたか?

解決

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

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

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

json.(@appuser, :user_auth_token, :id)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top