일반 페이지 요청과 마찬가지로 모델 유효성 검사를 생성하지 않고 컨트롤러의 JSON을 통해 유효성 검사 메시지를 보내면 어떨까요? 당신이 contact.rb에 고유 이메일하지 않고 저장에서 "접촉"을 방지하려는 경우 예를 들어,
validates :email, :uniqueness => true
를 추가하고 컨트롤러의 작성 방법, 당신은 레일 발판 발전기 같은 것을 할 수있는 것 :
# POST /contacts
# POST /contacts.json
def create
@contact = Contact.new(params[:contact])
respond_to do |format|
if @contact.save
format.html { redirect_to @contact, notice: 'Contact was successfully created.' }
format.json { render json: @contact, status: :created, location: @contact }
else
format.html { render action: "new" }
format.json { render json: @contact.errors, status: :unprocessable_entity }
end
end
end
자바 스크립트는 다음 status
을 테스트하고 그에 따라 대응할 것입니다.
:
이 답변 주셔서 감사합니다 거기에 좋은 railscast이 있습니다 .. :) – boddhisattva