data-method links don't work under nav dropdowns #343

Closed
mhuggins opened this Issue Aug 21, 2012 · 15 comments

Projects

None yet
@mhuggins

It appears that data-method links (specifically for a :delete action to destroy a session) does not work as part of a navigation link within ul.dropdown-menu. If I copy the link code verbatim into the navigation itself (i.e.: it appears under ul.nav), then the link works perfectly fine.

The issue is only occurring when using twitter-bootstrap-rails from git master HEAD (specifically ref efc2fdc139f9, which includes the update for Twitter Bootstrap v2.1.0). If I switch back to twitter-bootstrap-rails version 2.1.1, then the issue goes away.

I've included relevant code below.

Gemfile

gem 'rails', '3.2.8'
gem 'jquery-rails'
gem 'devise'
gem 'therubyracer'
# gem 'twitter-bootstrap-rails', '2.1.1'                                    # this version works
gem 'twitter-bootstrap-rails', github: 'seyhunak/twitter-bootstrap-rails'   # this version fails

routes.rb

devise_for :users

layouts/application.html.haml

.container.nav-collapse
  -if user_signed_in?
    %ul.nav.pull-right
      -# This link works:
      %li= link_to 'Logout', destroy_user_session_path, method: :delete
      %li.dropdown
        %ul.dropdown-menu
          -# This link fails:
          %li= link_to 'Logout', destroy_user_session_path, method: :delete

The specific routing error message is:

No route matches [GET] "/users/sign_out"

Apparently something in twitter-bootstrap-rails is preventing jquery-rails from processing the data-method="delete" attribute correctly on ONLY the dropdown menu version of the link.

@benbinary

+1

@ericcf
ericcf commented Aug 23, 2012

It's true for other methods such as :put too, and it seems to be a bootstrap issue: twbs/bootstrap#4497

@cebartling

I'm seeing similar issues with the nav dropdown with regular links. Probably connected to twbs/bootstrap#4497 issue.

@guilherme

+1

@mhuggins

User mfansler provided a workaround in the other issue, which works when I add it to my application.js.

$('body')
  .off('click.dropdown touchstart.dropdown.data-api', '.dropdown')
  .on('click.dropdown touchstart.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() });

Not ideal, but will work until Bootstrap 2.1.1 is released.

@ybart
ybart commented Aug 31, 2012

Workaround confirmed working. Thanks !

@amejiarosario

I tried the workaround but didn't work! So, I just went back to v2.1.0 and it's working again!
gem "twitter-bootstrap-rails", '=2.1.0', :group => :assets

@sewid
sewid commented Sep 2, 2012

+1

@davidaragao

+1

@pedronaves

+1

@javjar
javjar commented Sep 4, 2012

+1

@taylorstrait

+1

@toadkicker
Contributor

This should be fixed from #364

@wikiziner

+1

@mhuggins mhuggins closed this Sep 17, 2012
@mhuggins

Thanks for the update, @toadkicker. I've gone ahead and closed this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment