Rails 3.2 사용. Rails의 오류를 Ajax 경고에 어떻게 표시 할 수 있을지 궁금하다.Ajax에서 Rails 오류 메시지 표시
# posts_controller.rb
def update
@post = Post.find(params[:id])
if @post.update_attributes(params[:name] => params[:value])
render :nothing => true
else
render :text => @post.errors.full_messages[0], :status => :unprocessable_entity
end
end
# _form.html.erb
$("#status_buttons button").click(function() {
$.ajax({
type: 'POST',
url: "<%= post_path(@trip) %>",
data: { _method: 'PUT', name: this.name, value: this.value },
error: function() {
alert(" *****************Rails error message here**********************");
}
});
});
기존 유효성 검사 오류 메시지가 alert()
에 나타납니다 : 여기 내 코드입니다. 어떤 생각?
감사합니다.