I am trying to create a link to destroy and entry in the DB using AJAX but I also want it to function without JavaScript enabled
However the following code
<%=link_to_remote 'Delete', :update => 'section_phone', :url => {:controller => 'phone_numbers', :action => 'destroy', :id => phone_number_display.id }, :href => url_for(:controller => 'phone_numbers', :action => 'destroy', :id => phone_number_display.id)%>
produces the output
<a href='#' onclick='new Ajax.Updater('section_phone', '/phone_numbers/destroy/1', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('b64efb643e49e9af5e2e195a90fd5a8b6b99ece2')}); return false;'>Delete</a>
For some reason the url_for does not work properly and the href tag is set to #. I do not know why this does not work since I am not notified of any errors in the log
Does anyone know why this could be?
Thank you
You’re missing curly braces around the options{} hash, which :update and :url belong to, to separate them from the html_options{} hash that :href belongs to.
Try this:
That’ll get the URL to show up as the href attribute of your link, but a GET request to your destroy action shouldn’t delete it. You’ll need something else (like what vrish88 suggests) so that you can make a GET request to the destroy action to get a form, then POST that form to actually delete the phone number.