Skip to content Skip to sidebar Skip to footer

Rails Edit Action Not Updating And Not Work Properly Using Ajax

I am trying to do two things: With Ajax render Edit form when a user clicks on Edit link/button Then after editing and they click on Update link/button, hide the form. ...but unf

Solution 1:

I give it all/dedicate it to @bkunzi01's comment under the post to the problem/question and that is what helped me solved it. So this is how I eventually solved it:

Error 1:

So according to what was suggested as I mentioned earlier, I had to redefine my edit.js.erb file to handle unique id of the edit in the row. So my edit.js.erb becomes:

$('#edit-clock-entry-<%= @clock_entry.id %> a').hide().parent().append("<%= j render 'form', clock_entry: @clock_entry %>")

Error 2:

I did not create update action with ajax and that made it behaved the way it behaved. So I created a file called update.js.erb to handle what happens when users hit the update button. So my update.js.erb becomes:

$('.refresh').bind('ajax:success', function () {
    $(this).hide().parent();
})

So this is what I have now shown in the image

image

Log also shows the right record was updated

log image

This fixed it for me.

Post a Comment for "Rails Edit Action Not Updating And Not Work Properly Using Ajax"