我的Rails应用程序中没有显示Bootstrap按钮下拉列表

时间:2014-04-08 22:38:55

标签: ruby-on-rails drop-down-menu twitter-bootstrap-2

My Rails 4应用程序具有以下项目的edit.html.haml视图:

%h1
  Edit Project
  .actions
    = link_to 'Browse', projects_path, :class => 'btn'
    = link_to 'View', project_path, :class => 'btn'
    - if ((@project.teams.map { |t| t.user_id }.include? current_user.id) || is_admin?)
      %a.btn.dropdown{:hfref => '#', :data => {:toggle => 'dropdown'}}
        = 'Time'
        %span.caret
        %ul.dropdown-menu{:role => 'menu', 'aria-labelledby' => 'dLabel'}
          %li
            = link_to 'Submitted', billables_path(:project_id => @project.id, :status => 'Submitted')
          %li
            = link_to 'Totalled', billables_path(:project_id => @project.id, :status => 'Totalled')
          %li
            = link_to 'Adjusted', billables_path(:project_id => @project.id, :status => 'Adjusted')
          %li
            = link_to 'Billed', billables_path(:project_id => @project.id, :status => 'Billed')
      = link_to 'Software', tools_path(:project_id => @project.id), :class => 'btn'
      = link_to 'Expense', expenses_path(:project_id => @project.id), :class => 'btn'
    = render :partial => 'team', :locals => { :project => @project }

= render :partial => 'form'

当我点击下面有四个菜单项的“时间”按钮时,我不确定为什么没有显示下拉菜单。浏览器控制台不显示任何错误。

2 个答案:

答案 0 :(得分:0)

您是否正在加载Bootstrap的javascript文件? 下拉列表与bootstrap.js中包含的下拉javaScript插件交互。

答案 1 :(得分:0)

我明白了。我正在为那些可能感兴趣的人发布我的解决方案。以下是修改后的代码,可以按照我的要求运行:

%h1
  Edit Project
  .actions
    = link_to 'Browse', projects_path, :class => 'btn'
    = link_to 'View', project_path, :class => 'btn'
    - if ((@project.teams.map { |t| t.user_id }.include? current_user.id) || is_admin?)
      %span.dropdown
        %a.dropdown-toggle{:role => 'button', :href => '#', :data => {:toggle => 'dropdown'}, :class => 'btn'}
          = 'Time'
          %b.caret
        %ul.dropdown-menu{:role => 'menu', 'aria-labelledby' => 'dLabel'}
          %li
            = link_to 'Submitted', billables_path(:project_id => @project.id, :status => 'Submitted')
          %li
            = link_to 'Totalled', billables_path(:project_id => @project.id, :status => 'Totalled')
          %li
            = link_to 'Adjusted', billables_path(:project_id => @project.id, :status => 'Adjused')
          %li
            = link_to 'Billed', billables_path(:project_id => @project.id, :status => 'Billed')
      = link_to 'Software', tools_path(:project_id => @project.id), :class => 'btn'
      = link_to 'Expense', expenses_path(:project_id => @project.id), :class => 'btn'
    = render :partial => 'team', :locals => { :project => @project }

= render :partial => 'form'

这确实是一个CSS和HTML问题。 1.注意下面的%span.dropdown -if .. 它确保链接或按钮与其余链接或按钮保持一致。通过这个微小的变化,一切正常。

@Papzord,谢谢你试图帮助我。