documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.com/jammit/
MIT License
1.16k stars 197 forks source link

Jammit package_assets breaking link_to with :method => delete #174

Closed sreid99 closed 13 years ago

sreid99 commented 13 years ago

I'm using jammit with a simple rails app. However, it breaks the following link_to, which I understand uses rails javascript :

<%= link_to 'Destroy', site, :confirm => 'Are you sure?', :method => :delete %>

On clicking, it issues a get rather than a delete.

The following assets.yml fails (even though I've turned most options off), but will work if I change to package_assets:off :

package_assets:on
embed_assets:off
compress_assets:off
gzip_assets:off
package_path:packages
javascript_compressor:closure

javascripts:
  common:
    - public/javascripts/*.js

stylesheets:
  common:
    - public/stylesheets/*.css
vandrijevik commented 13 years ago

@sreid99, what do you exactly mean by “The following assets.yml fails”? How are you including javascripts in your application template?

sreid99 commented 13 years ago

Hi,

When I click on the link, it acts as a get rather than a delete (and ends up at the wrong page). I get the same effect if javascript is not included. If I just change package_assets: to off (and re-run jammit), the link then works correctly.

I include javascript using :

<%= include_javascripts :common %> <%= yield :javascripts %>

vandrijevik commented 13 years ago

What is <%= yield :javascripts %> for?

sreid99 commented 13 years ago

Got it from here : http://slowcop.com/how-to-combine-your-css-and-javascript-files-in-rails-with-jammit

It defers loading the javascript.

I just removed it, but no difference.

jashkenas commented 13 years ago

Sounds like a configuration or a Rails problem, not a Jammit problem, I'm afraid. We can't help you if you're not actually loading the JavaScript files you want to be loading.

sreid99 commented 13 years ago

Earlier I mentioned that if I just changed package_assets: to off - no other changes - then the rails javascript works. Surely that means jammit could be the reason the javascript stopw working ?

Forget about the yield - removing it made no difference.

jashkenas commented 13 years ago

No ... that means you need to debug the reason why your JavaScript isn't working -- I can't remotely intuit if your script tags aren't being loaded ... if they are being loaded but the JS isn't parsing ... if the JS is parsing but the jQuery isn't being hooked up ... whatever the case may be.

sreid99 commented 13 years ago

It's not my javascript. I'm only using the default rails3 javascript files.

I rechecked it, and the when I enable package_assets, the javascript on the page correctly changes to a single common.js file as I'd expect. However, it doesn't hit any of my breakpoints when I click on destroy. If package_assets is off, I can get a breakpoint when I hit cancel after the ok/cancel confirm dialogue appears.

sreid99 commented 13 years ago

Is it possible to reopen this so it doesn't get missed ?

jashkenas commented 13 years ago

Sure -- if you can give me a real bug report to work with. Just telling me that your JavaScript isn't working isn't particularly helpful: you need to look into why it isn't working.

... and so on.

sreid99 commented 13 years ago

This is a "real bug report". Something doesn't work when I use Jammit, and I tried to explain how to recreate the issue. Have you tried to recreate this ?

It seems like the relevant code is in the standard rails.js file. I explained I already tried some breakpoints with no success. That's as far as I can go on debugging - I'm not a javascript expert - unless you can describe how I can get the additional information you need.

All I can add is the html is : <a rel="nofollow" data-method="delete" data-confirm="Are you sure?" href="/sites/120">Destroy</a> Don't see any error on the console.