Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用活动模型序列化程序对简单json呈现的异常响应_Ruby On Rails_Json_Ruby On Rails 4_Active Model Serializers - Fatal编程技术网

Ruby on rails 使用活动模型序列化程序对简单json呈现的异常响应

Ruby on rails 使用活动模型序列化程序对简单json呈现的异常响应,ruby-on-rails,json,ruby-on-rails-4,active-model-serializers,Ruby On Rails,Json,Ruby On Rails 4,Active Model Serializers,我的Rails 4项目中有以下文件: 列出\u controller.rb class Api::V1::ListsController < Api::V1::ApiController before_action :set_list, only: [:show] attr_accessor :list def show respond_with list end private def set_list @list = List.where

我的Rails 4项目中有以下文件:

列出\u controller.rb

class Api::V1::ListsController < Api::V1::ApiController
  before_action :set_list, only: [:show]

  attr_accessor :list

  def show
    respond_with list
  end

  private

  def set_list
    @list = List.where(id: params[:id]).first
    render_list_not_found if @list.nil?
  end

  def render_list_not_found
    render json: { "list" => { message: "List not found" } }, status: 404
  end

end
class ListSerializer < ActiveModel::Serializer
  embed :ids, include: true

  attributes :id, :title, :start_date, :end_date

  has_many :items
end
但是,你可以这样做:

 {
    "lists": [
        [
            "list",
            [
                [
                    "message",
                    "List not found."
                ]
            ]
        ]
    ]
}

知道为什么会发生这种情况吗?

即使使用简单的渲染,似乎也在调用活动的模型序列化程序。我使用的是gem的
0.9.1
,但降级到
0.9.0
似乎起到了作用。很奇怪

 {
    "lists": [
        [
            "list",
            [
                [
                    "message",
                    "List not found."
                ]
            ]
        ]
    ]
}