Ruby on rails 使用活动模型序列化程序对简单json呈现的异常响应
我的Rails 4项目中有以下文件: 列出\u controller.rbRuby 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
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."
]
]
]
]
}