I have the following mongoid model class:
class Exercise
include Mongoid::Document
field :name, :type => String
field :description, :type => String
belongs_to :group
validates_presence_of :name, :description, :group
end
And I have the following controller:
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
The model saves fine when valid but when the following line is ran:
respond_with(@exercise.errors, :status => :unprocessable_entity)
I get the following error
undefined method `model_name' for ActiveModel::Errors:Class
The errors collection is populated so I think my respond_with syntax is wrong.