0

我似乎无法让导航栏崩溃在我的 Rails 应用程序上工作

application.html.erb 是

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="assets/stylesheets/bootstrap-responsive.css" rel="stylesheet">
    <%= analytics_init if Rails.env.production? %>
  <title>Guidelines for Me</title>

  <%= stylesheet_link_tag    "application", :media => "all" %>
  <%= javascript_include_tag "application" %>
  <%= csrf_meta_tags %>

  <script type="text/javascript">
function clearDefault(el) {
if (el.defaultValue==el.value) el.value = ""
}
function clearText(){
    search = $('.search-query');
    if (search.defaultValue==search.value)
    search.value = ""
}

</script>
</head>
<body>

    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="navbar-inner">
            <% if Guideline.count % 100 ==0 %>
                <%= link_to "#{Guideline.count}" " guidelinesforme available - yay!", guidelines_path, :class => 'brand' %>
            <% else %>

                    <%= link_to "#{Guideline.count}" " guidelinesforme available!", guidelines_path, :class => 'brand' %>
            <% end %>


            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        </a>


    <div class="nav-collapse collapse">

            <ul class="nav">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        List guidelines by...
                        <b class="caret"></b>
                        </a>


                <ul class="dropdown-menu">

                    <li><%= link_to "...Topic", topics_path %></li>
                    <li><%= link_to "...Hospital", hospitals_path %></li>
                    <li><%= link_to "...Specialty", specialties_path %></li>
                    </li>   
                </ul>

                    <% if user_signed_in? %>
                    <li><%= link_to "Favourites", favourites_path %></li>
                    <% else %>  
                    <li><%= link_to "Favourites", register_path %></li>
                    <% end %>
            </ul>

            <ul class="nav pull-right">

                    <li class="dropdown">
                     <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    <% if user_signed_in? %>
                    <%= current_user.first_name %>
                    <% else %>
                    Log in or Sign up
                    <% end %>
                    <b class="caret"></b>
                    </a>

                <ul class="dropdown-menu">

                    <% if user_signed_in? %>
                        <li ><%= link_to "Edit profile", edit_path %></li>
                        <li> <%= link_to "Log out", logout_path %></li>
                        <li> <%= link_to "My additions", profiles_show_path(id: current_user.profile_name) %></li>
                    <% else %>
                        <li><%= link_to "Log in", login_path %></li>
                        <li><%= link_to "Sign Up", register_path %></li>
                    <% end %>

                    <li><%= link_to "About us", about_path %></li>
                </li>
                </ul>



                    <li class="nav pull-right">
                    <%= form_tag guidelines_path, :class => 'navbar-search pull-right', :onSubmit=>"clearText(this)",:method => :get do %>  

                    <%= text_field_tag :search, params[:search], :class => 'search-query input-small', :placeholder=>"Search", :ONFOCUS=>"clearDefault(this)" %> <% end %></li>
            </ul>
        </div>
        </div>
    </div>

    <div class="container">
        <% flash.each do |type, message| %>
            <div class="alert <%= flash_class type %>">
                <button class="close" data-dismiss="alert">x</button>
                <%= message %>
    </div>
        <% end %>


        <%= yield %>

    </div>
</body>

<script src="/assets/js/bootstrap-dropdown.js"></script>
</html>

在我的 application.js

$(".collapse").collapse()

我没有使用 bootstrap gem,我只是手动添加了 bootstrap。我不确定这是否是插件要求的问题或如何解决这个问题。

谢谢

4

1 回答 1

0

你需要添加

<script src="/assets/js/bootstrap-dropdown.js"></script>

在模板的末尾

$(".collapse").collapse()

在 your_scripts.js 里面,不在你的 style.css 文件中

于 2013-03-01T01:44:43.240 回答