Why is my dropdown menu with Bootstrap not working?

前端 未结 6 1091
野性不改
野性不改 2021-02-08 07:54

In my Rails application, I have the following code for a dropdown menu:

&l
6条回答
  •  一个人的身影
    2021-02-08 08:20

    I've got in the same problem with default Rails and twitter-bootstrap-rails gem installation.

    Direct call of dropdown initialisation works indeed, but it looks like kind of a workaround for me. So, I continued to search for the answers and was able to find the one that looks more appropriate:

    I have solved this issue. I add following code in users.js.coffee:

    jQuery ->
      $('.dropdown-toggle').dropdown()  
    

    Solution was found here. Thus, I added this code to app/assets/javascripts/bootstrap.js.coffee, so the final code in it looks like the following:

    jQuery ->
      $("a[rel~=popover], .has-popover").popover()
      $("a[rel~=tooltip], .has-tooltip").tooltip()
      $('.dropdown-toggle').dropdown()
    

    And right after this dropdown in navbar started to work exactly as expected.

提交回复
热议问题