I have an editor where users can edit and paste text, and the changes are automatically saved in the server, via AJAX.
Through JS I monitor the state of the textarea, like this:
$("#editor-area").bind "input propertychange", ->
content = $("#editor-area").val()
updateRequest = $.ajax(
url: url
data:
texto:
contenido: content
type: "PUT"
)
Which I extracted from here, answer by Emma Li.
The moment I write a single character, the console shows the same information when one call is performed and processed, but many times. They are so many that my console is overrun and starts overwriting past calls, doing the exactly same thing: updating the record with the new text.
The update method in the controllers looks like
def update
respond_to do |format|
if @text.update(text_params)
format.html {
redirect_to user_text_path(current_user, @text)
}
format.json { render :json => @texto }
else
format.html { redirect_to edit_user_path(@user, @text) }
end
end
end
There also a before_filter
for that option
def set_text_and_user
@text = get_stuff_from_Db
@user = @text.user
end
I've been trying to debug this thing, but it has defeated me so far. Have any idea what could be causing this?