I'm doing an ajax call in rail to update a flag in my database.
For some reason, the request is done twice.
the only difference between the 2 calls in the log is this:
Started PUT "/negotiations/groupprocurement_validation_toggle?id=1504" for 127.0.0.1 at 2011-01-20 22:28:39 +0100
Processing by NegotiationsController#groupprocurement_validation_toggle as JS
Started PUT "/negotiations/groupprocurement_validation_toggle?id=1504" for 127.0.0.1 at 2011-01-20 22:28:40 +0100
Processing by NegotiationsController#groupprocurement_validation_toggle as /
So the difference is in the "as JS" or "as /".
I have no clue what it means :(
here's the link
<%= link_to truefalse(validation_status.validated_global, true), validate_global_negotiations_path(:id => validation_status), :method => :put, :remote => true, :id => "validation_#{validation_status.id}" %>
The Javascript
$('a[id^=validation_]').live('click', function(){
var line_id = $(this).attr('id').replace('validation_','');
$.ajax({
url: '/negotiations/gp_validation_toggle?id=' + line_id,
type: "PUT",
success: function(data){
$('#validation_image_' + line_id).html(img_result);
$('#container').prepend(msg_result)
$('#flash_notice').delay(3000).fadeOut('slow');
},
beforeSend: function(){
$('#validation_image_' + line_id).html('<img src="/images/loading_round.gif">');
}
});
return false;
});
and in the controller, I have
respond_to :html, :js, :csv
and
def gp_validation_toggle
@negotiation = Negotiation.find(params[:id])
@negotiation.validated_global = !@negotiation.validated_global
if @negotiation.save
flash[:notice] = "Modification saved"
else
flash[:notice] = "Oops something went wrong"
end
end
what am I doing wrong?
thanks, P.
try using delegate instead of live