我的控制器中有以下内容:
def create
equipment = Equipment.create(:name => params[:name])
errors = equipment.errors.messages
puts "equipment errors: " + errors.inspect
respond_to do |format|
format.json { render :json => @equipment }
end
end
“看跌”的回应是:
equipment errors: {:name=>["has already been taken"]}
如何解析错误并获取消息?
谢谢