4

I'm trying to make this be a link to a destroy action for a note :

 <%= link_to "delete", @note, :method => :delete, :confirm => "Are you sure" %>

This just routes to the note and doesn't go through to the destroy action... Whereas this:

 <%= button_to "delete", @note, :method => :delete, :confirm => "Are you sure" %>

Does route properly. I'm using jQuery 1.7 and I installed the gem 'jquery-rails', '>= 1.0.12' (which includes the jquery_ujs.js file).

What fixes are there to make link_to work properly? For some reason, I have an older app on which these link_to links work, but I can't remember why.. Any pointers?

(I really don't want to use button_to.. this styling is annoying, and I'm sure that there must be a way to do this..)

UPDATE: Using Rails 3.0.9

jay
  • 12,066
  • 16
  • 64
  • 103

1 Answers1

11

You're not loading the jquery_ujs.js file from jquery-rails. Ensure that you're requiring both jquery and jquery_ujs in your layout.

These two files are typically included in the app/assets/javascripts/application.js file, which contains this content:

//= require jquery
//= require jquery_ujs
//= require_tree .

If you're not including this in your layout with this line:

<%= javascript_include_tag "application" %>

Then both the jquery.js and jquery_ujs.js files won't be included, and so the :method => :delete requests will not work as intended.

Ryan Bigg
  • 106,965
  • 23
  • 235
  • 261
  • this didn't work for me.. I didn't have the application.js file before, but I added it with no changes seen. Also the confirm message doesn't pop up, but jquery does work on other pages for other functionality. (Also I'm using an older version of rails, with javascripts still in public/javascripts) – jay Mar 30 '12 at 15:26
  • FYI the confirm message doesn't show up either.. it seems that none of the data- things work. BUT jquery is working ( eg $("body").slideUp(); works) – jay Mar 30 '12 at 16:49
  • Hey, I noticed that you're right, but I still have a problem with remotely loaded content having full functionality.. Please see this follow up question if you can, thanks !! http://stackoverflow.com/questions/9950332/jquery-ujs-not-functioning-when-i-remotely-load-partials – jay Mar 30 '12 at 21:00