Show Rails error message in Ajax alert

stevian1

New Member
Using Rails 3.2. I wonder how can we push the error from Rails to show in the Ajax alert. Here is my code:\[code\]# posts_controller.rbdef 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 endend# _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**********************"); } });});\[/code\]The conventional validation error message should appear in the \[code\]alert()\[/code\]. Any idea?Thanks.
 
Back
Top