0
我入门到Ajax和红宝石和我的问题是,我不能得到错误信息,当我与刷新Ruby on Rails的Ajax错误处理
控制器
class InvitesController < ApplicationController
def request_invite
render_404 unless request.xhr?
@invitation = Invite.new(params[:invite])
if @invitation.save
@return = { :error => false, :response => "OK" }
else
@return = { :error => true, :response => "BAD" }
end
render :json => ActiveSupport::JSON.encode(@return)
end
end
通过后提交表单我能得到
所以现在我有自定义错误,但我想,以取代“BAD”与实际的错误,形式回报...
模型
class Invite < ActiveRecord::Base
validates :email, :presence => true, :uniqueness => true
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
end
我该怎么做?