Thank you for looking at this. I'm quite the beginner, but I've been searching online for hours, but answer is eluding me.
I'm trying to update my rails app based on a click that occurs in my view. The click is registered, the AJAX is submitted (confirmed by Firebug), but ultimately my database is not updated. What going wrong?
Basically I'm trying to update the Goal object's Active attribute. It doesn't matter if I use the PUT type or the one in the actual code, or which way the parameters are being sent.
$.ajax({
url: '/goals/'+this.id,
data: { _method:'PUT', 'id':this.id, 'active':state },
//data: 'id='+this.id+'Active='+state,
type: 'POST'});
On the other end I have a vanilla update controller:
def update
@goal = current_user.goals.find(params[:id])
respond_to do |format|
if @goal.update_attributes(params[:goal])
format.html { redirect_to @goal, notice: 'Goal was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @goal.errors, status: :unprocessable_entity }
end
end
end
Thank you very much!