0

我正在整理一个来自 One Month Rails 的基本网站,但似乎无法弄清楚如何让导航栏显示在顶部。我花了几个小时,想去社区。这是来自 _header.html.erb 的代码(使用 bootstrap sass)

<div class="navbar navbar">
    <div class="navbar-inner">
        <div class="container">
            <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>
             <a class="brand" href="#">Project name</a>

                <div class="nav-collapse collapse">
                    <ul class="nav">
                        <li>
                            <%= link_to 'Home',  root_path %>
                        </li>
                        <li>    
                            <%= link_to 'About',  about_path %>
                        </li>
                    </ul>
                    <ul class="nav pull-right">
                                <li><%= link_to 'Login',  '#' %></li>
                    </ul>
                </div>
        </div>
    </div>
</div> 

以下是 application.html.erb 选项卡中的代码:

<!DOCTYPE html>
<html>
    <head>
        <body>
          <title>One Month Rails</title>
          <%= stylesheet_link_tag    "application", :media => "all" %>
          <%= javascript_include_tag "application" %>
          <%= csrf_meta_tags %>
        <%= tag :meta, name: "viewport", content: "width=device-width, initial-scale=1.0" %>
        </head>
        <body>
        <%= render 'layouts/header' %>
        <div class="container">
        <%= yield %>
        <%= render 'layouts/footer' %>
    </div>
    </body>
</html>
4

1 回答 1

2

您似乎在application.html.erb. 但是大多数现代浏览器会在加载页面时为您修复这些错误。这是一个更好的版本:

<!DOCTYPE html>
<html>
    <head>
        <title>One Month Rails</title>
        <%= stylesheet_link_tag    "application", :media => "all" %>
        <%= javascript_include_tag "application" %>
        <%= csrf_meta_tags %>
        <%= tag :meta, name: "viewport", content: "width=device-width, initial-scale=1.0" %>
    </head>
    <body>
        <%= render 'layouts/header' %>
        <div class="container">
            <%= yield %>
            <%= render 'layouts/footer' %>
        </div>
    </body>
</html>

您还应该确保您_header.html.erbapp/views/layouts/.

最后,不要忘记将 bootstrap 的 css 文件添加到app/assets/stylesheets/.

于 2013-07-30T02:44:19.003 回答