Search code examples
javascriptjqueryruby-on-railsbootstrap-modalpreventdefault

When click on modal link, "b.preventDefault is not a function" appears


I am working on Rails with haml format, and I have a table which has in the last column a button (link) that launches a modal:

= link_to('#', 'data-toggle' => 'modal', 'data-target' => '#team_modal', 'data-project' => project.id) do %span {
    class: 'glyphicon glyphicon-tasks',
    'aria-hidden' => 'true',
    'aria-hidden' => 'true',
    'data-toggle' => "tooltip",
    'title' => 'Team',
    'data-project' => project.id
}

When I click on it, the modal shows up, then the following error also appears at the console:

Uncaught TypeError: b.preventDefault is not a function
 b.hide @ bootstrap.min.js?body=1:7
 b.toggle @ bootstrap.min.js?body=1:7
 (anonymous function) @ bootstrap.min.js?body=1:7
 jQuery.extend.each @ jquery.js?body=1:612
 jQuery.fn.jQuery.each @ jquery.js?body=1:242
 a.fn.modal @ bootstrap.min.js?body=1:7
 (anonymous function) @ bootstrap.min.js?body=1:7
 jQuery.event.dispatch @ jquery.js?body=1:3059
 jQuery.event.add.elemData.handle.eventHandle @ jquery.js?body=1:2677

How can I fix this?


Solution

  • After several attempts, finally I removed the duplications like:

    config.assets.precompile << "redesign/bootstrap.js
    

    beside this, I removed the pure scripts and kept the minimal scripts, given:

    config.assets.precompile << "redesign/bootstrap.css"
    config.assets.precompile << "redesign/bootstrap.min.css"
    config.assets.precompile << "redesign/bootstrap.js"
    config.assets.precompile << "redesign/bootstrap.min.js"
    

    to have this:

    config.assets.precompile << "redesign/bootstrap.min.css"
    config.assets.precompile << "redesign/bootstrap.min.js"
    

    Note: I don't know what this does but it works. If someone knows why keeping the minimal scripts the error desappear, please comment it.