2015-04-05 31 views
0

我是RoR的新手。在這個應用程序中,我有一個名爲Clubs的模型和頂部的導航欄。但是,由於某些原因,應用程序呈現時,俱樂部的每個視圖都會成爲導航欄的一部分。這裏有一個截圖給你看我的意思: enter image description hereRuby on Rails-模型視圖不知何故成爲導航欄的一部分

這是我的代碼:

<html> 
    <head> 
     <meta charset="utf-8"> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <title>BHSClubs</title> 
     <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 
     <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 
     <%= csrf_meta_tags %> 
    </head> 
    <body> 
     <div class="navbar navbar-fixed-top"> 

       <!-- Brand and toggle get grouped for better mobile display --> 
       <div class="navbar-inner"> 
        <div class="container"> 
         <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> 
          <span class="sr-only">Toggle navigation</span> 
          <span class="icon-bar"></span> 
          <span class="icon-bar"></span> 
          <span class="icon-bar"></span> 
         </button> 
         <a class="navbar-brand" href="#">Brookline High School</a> 
        <!-- Collect the nav links, forms, and other content for toggling --> 
        <ul class="nav navbar-nav"> 
         <li> 
          <a href="#">About</a> 
         </li> 
         <li> 
          <a href="#">Services</a> 
         </li> 
         <li> 
          <a href="#">Contact</a> 
         </li> 
         <ul class="navbar-text pull-right"> 
          <% if user_signed_in? %> 
          Logged in as <strong><%= current_user.email %></strong>. 
          <%= link_to 'Edit profile', edit_user_registration_path, :class => 'navbar-link' %> | 
          <%= link_to "Logout", destroy_user_session_path, method: :delete, :class => 'navbar-link' %> 
          <% else %> 
          <%= link_to "Sign up", new_user_registration_path, :class => 'navbar-link' %> | 
          <%= link_to "Login", new_user_session_path, :class => 'navbar-link' %> 
          <% end %> 
          <% if notice %> 
          <p class="alert alert-success"> 
           <%= notice %> 
          </p> 
          <% end %> 
          <% if alert %> 
          <p class="alert alert-danger"> 
           <%= alert %> 
          </p> 
          <% end %> 
          <%= yield %> 
         </ul> 
        </ul> 
       </div> 
       <!-- /.navbar-collapse --> 
      </div> 
      <!-- /.container --> 
     </div> 
    </body> 
</html> 

Show方法

<div class="container"> 

<div class="row"> 

    <div class="col-md-3"> 
     <p class="lead"> 
      <%= @club.name %> 
     </p> 
     <div class="list-group"> 
      <a href="#" class="list-group-item active">Information</a> 
      <a href="#" class="list-group-item">Announcements</a> 
     </div> 
    </div> 

    <div class="col-md-9"> 

     <div class="thumbnail"> 
      <img class="img-responsive" src="http://placehold.it/800x300" alt=""> 
      <div class="caption-full"> 
       <p id="notice"> 
        <%= notice %> 
       </p> 

       <p> 
        <h4>Name:</h4> 
        <%= @club.name %> 
       </p> 

       <p> 
        <strong>Description:</strong> 
        <%= @club.description %> 
       </p> 

       <p> 
        <strong>Location:</strong> 
        <%= @club.location %> 
       </p> 

       <p> 
        <strong>Picture:</strong> 
        <%= image_tag(@club.picture_url, :width => 600) if @club.picture.present? %> 
       </p> 

       <%= link_to 'Edit', edit_club_path(@club) %> | 
       <%= link_to 'Back', clubs_path %> 
      </div> 
     </div> 

    </div> 

</div> 

任何幫助表示讚賞。

回答

1

您正在渲染您的Clubs <%= yield %>在應用程序導航欄!內,因此您必須將<%= yield %>放在導航元素之外,另一個引導元素.container內。

<html> 
    <head> 
     <meta charset="utf-8"> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <title>BHSClubs</title> 
     <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 
     <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 
     <%= csrf_meta_tags %> 
    </head> 
    <body> 
     <div class="navbar navbar-fixed-top"> 
      <!-- Brand and toggle get grouped for better mobile display --> 
      <div class="navbar-inner"> 
       <div class="container"> 
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> 
        <span class="sr-only">Toggle navigation</span> 
        <span class="icon-bar"></span> 
        <span class="icon-bar"></span> 
        <span class="icon-bar"></span> 
        </button> 
        <a class="navbar-brand" href="#">Brookline High School</a> 
        <!-- Collect the nav links, forms, and other content for toggling --> 
        <ul class="nav navbar-nav"> 
         <li> 
          <a href="#">About</a> 
         </li> 
         <li> 
          <a href="#">Services</a> 
         </li> 
         <li> 
          <a href="#">Contact</a> 
         </li> 
         <ul class="navbar-text pull-right"> 
          <% if user_signed_in? %> 
          Logged in as <strong><%= current_user.email %></strong>. 
          <%= link_to 'Edit profile', edit_user_registration_path, :class => 'navbar-link' %> | 
          <%= link_to "Logout", destroy_user_session_path, method: :delete, :class => 'navbar-link' %> 
          <% else %> 
          <%= link_to "Sign up", new_user_registration_path, :class => 'navbar-link' %> | 
          <%= link_to "Login", new_user_session_path, :class => 'navbar-link' %> 
          <% end %> 
          <% if notice %> 
          <p class="alert alert-success"> 
           <%= notice %> 
          </p> 
          <% end %> 
          <% if alert %> 
          <p class="alert alert-danger"> 
           <%= alert %> 
          </p> 
          <% end %> 
         </ul> 
        </ul> 
       </div> 
       <!-- /.navbar-collapse --> 
      </div> 
      <!-- /.container --> 
     </div> 
     <div class="container"> 
      <div class="row"> 
       <div class="col-sm-12"> 
        <%= yield %> 
       </div> 
      </div> 
     </div> 
    </body> 
</html> 
+0

我看到的經典新手錯誤。非常感謝! – StephenChen 2015-04-05 18:32:43