我的rails应用程序上的twitter bootstrap navbar collapse

时间:2013-03-01 01:38:28

标签: ruby-on-rails ruby-on-rails-3 twitter-bootstrap

我似乎无法让导航栏崩溃以在我的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。我不确定这是插件要求的问题还是如何解决这个问题。

由于

1 个答案:

答案 0 :(得分:0)

你需要添加

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

在模板的末尾

$(".collapse").collapse()

位于your_scripts.js内,而不在style.css文件中