我有以下 mongoid 模型类:
class Exercise
include Mongoid::Document
field :name, :type => String
field :description, :type => String
belongs_to :group
validates_presence_of :name, :description, :group
end
我有以下控制器:
class ExercisesController < ApplicationController
respond_to :json
def create
@exercise = Exercise.create(params[:exercise])
if @exercise.save
respond_with @exercise
else
respond_with(@exercise.errors, :status => :unprocessable_entity)
end
end
end
该模型在有效但运行以下行时保存良好:
respond_with(@exercise.errors, :status => :unprocessable_entity)
我收到以下错误
ActiveModel::Errors:Class 的未定义方法“model_name”
错误集合已填充,因此我认为我的 respond_with 语法错误。