-
-
Save neerajsingh0101/1203326 to your computer and use it in GitHub Desktop.
making jquery-ujs work with delete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// index.html.erb page for users | |
<%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete, :remote => true, 'data-type' => 'json' %> | |
//users_controller | |
def destroy | |
@user = User.find(params[:id]) | |
respond_to do |format| | |
format.html { redirect_to(users_url) } | |
format.js { | |
render :json => {'name' => "#{@user.name} has been deleted"} | |
} | |
end | |
end | |
//application.js | |
$('a[data-method="delete"]').live('ajax:success', | |
function(e, data, textStatus, jqXHR){ | |
alert(data.name + ' has been deleted'); | |
} | |
); | |
You are right. Line 22 should just say
alert(data.name);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lines 12 and 22 seem to be doing the same thing (ie. they have 'has been deleted' in the return string).
Did you mean to have line 12 without 'has been deleted' in the return string?
Line 12: render :json => {'name' => "#{@user.name}"}