2012-10-24 53 views
1

我无法理解这是怎么发生的。我的网页上显示源开始这样的 - 是的,这是HTML的一开始,我有双重检查它在Chrome和Safari ...Rails在生成HTML之前<DOCTYPE

 </div> 
    </div> 
    </div> 
<!DOCTYPE html> 
<html> 
<head> 
    <title>Rstest</title> 
    <link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" /> 
<link href="/assets/bootstrap_and_overrides.css?body=1" media="all" rel="stylesheet" type="text/css" /> 
<link href="/assets/custom.css?body=1" media="all" rel="stylesheet" type="text/css" /> 

然而,我application.html.erb开始喜欢这个:

<!DOCTYPE html> 
<html> 
<head> 
    <title>Rstest</title> 
    <%= stylesheet_link_tag "application", :media => "all" %> 
    <%= javascript_include_tag "application" %> 
    <%= csrf_meta_tags %> 

我想不出,将导致此情景......

这里有一些更多的细节,从日志:

Rendered reports/report.html.erb within layouts/reptabs (1093.5ms) 
Rendered layouts/application.html.erb (12.8ms) 

这里是相关的观点:

application.html.erb:

<!DOCTYPE html> 
<html> 
<head> 
    <title>Rstest</title> 
    <%= stylesheet_link_tag "application", :media => "all" %> 
    <%= javascript_include_tag "application" %> 
    <%= csrf_meta_tags %> 
</head> 
<body> 

<header class="navbar navbar-fixed-top"> 
    <div class="navbar-inner"> 
    <div class="container"> 
     <%= link_to "Repeat Survey", '#', id: "logo" %> 
     <nav> 
     <ul class="nav pull-right"> 
      <li><%= link_to "Home", '#' %></li> 
      <li><%= link_to "About", '#' %></li> 
      <li><%= link_to "Contact", '#' %></li> 
      <li><%= link_to "Help", '#' %></li> 
     </ul> 
     </nav> 
    </div> 
    </div> 
</header> 

<div class="container"> 
    <%= content_for?(:content) ? yield(:content) : yield %> 
</div> 

</body> 
</html> 

reptabs.html.erb:

<% content_for :content do %> 
    <div class="container"> 
    <ul class="nav nav-tabs"> 
     <li><%= link_to "Reports", report1_path(@program_id) %></li> 
     <li><%= link_to "Settings", edit_program_path(@program_id) %></li> 
     <li><%= link_to "Rounds", program_rounds_path(@program_id) %></li> 
     <li><%= link_to "Participants", program_participants_path(@program_id) %></li> 
     <li><%= link_to "Questions", program_questions_path(@program_id) %></li> 
    </ul> 

    <div class="container"> 
     <div class="row"> 
     <div class="span2"> 
      <ul class="nav nav-pills nav-stacked"> 
      <li><%= link_to("q r p", report1_path(@program_id)) %></li> 
      <li><%= link_to("r q p", report2_path(@program_id)) %></li> 
      <li><%= link_to("p r q", report3_path(@program_id)) %></li> 
      <li><%= link_to("p q r", report4_path(@program_id)) %></li> 
      </ul> 
     </div> 
     <div class="span9"> 
      <%= content_for?(:reptabs_content) ? yield(:reptabs_content) : yield %> 
      <% end %> 
     </div> 
    </div> 
    </div> 
<%= render :template => 'layouts/application' %> 

report.html.erb:

<h2>Report</h2> 
    <p> 
    <%= @presenter.to_s %> 
    </p> 

<table class="table table-striped"> 
    <thead> 
    <tr> 
     <th>....</th> 
     <% @presenter.headers.each do |hdr| %> 
     <th><%= hdr %></th> 
     <% end %> 
    </tr> 
    </thead> 
    <tbody> 
    <% @presenter.rows.each do |row_instance| %> 
     <tr> 
     <td><%= @presenter.row_label(row_instance) %></td> 
     <% @presenter.cols.each do |col_instance| %> 
      <td> 
      <%= @presenter.cell(row_instance, col_instance).count %> => 
      <%= @presenter.cell(row_instance, col_instance).join(", ") %> 
      </td> 
     <% end %> 
     </tr> 
    <% end %> 
    </tbody> 
</table> 

我不知道我是否在用我的content_for语句搞乱了一些东西?

+0

布局文件被命名为application.htmm.erb或application.html.erb?在任何情况下,我建议你改正错误的错误是它在你的应用程序中是正确的。 –

+0

错字,谢谢,修正。 – pitosalas

+0

你检查过哪个视图实际上在' HungryCoder

回答

1

你应该将在content_for环降到底这样 reptabs.html.erb:

<% content_for :content do %> 
    <div class="container"> 
    <ul class="nav nav-tabs"> 
     <li><%= link_to "Reports", report1_path(@program_id) %></li> 
     <li><%= link_to "Settings", edit_program_path(@program_id) %></li> 
     <li><%= link_to "Rounds", program_rounds_path(@program_id) %></li> 
     <li><%= link_to "Participants", program_participants_path(@program_id) %></li> 
     <li><%= link_to "Questions", program_questions_path(@program_id) %></li> 
    </ul> 

    <div class="container"> 
     <div class="row"> 
     <div class="span2"> 
      <ul class="nav nav-pills nav-stacked"> 
      <li><%= link_to("q r p", report1_path(@program_id)) %></li> 
      <li><%= link_to("r q p", report2_path(@program_id)) %></li> 
      <li><%= link_to("p r q", report3_path(@program_id)) %></li> 
      <li><%= link_to("p q r", report4_path(@program_id)) %></li> 
      </ul> 
     </div> 
     <div class="span9"> 
      <%= content_for?(:reptabs_content) ? yield(:reptabs_content) : yield %> 
      <!--not here --> 
     </div> 
    </div> 
    </div> 
<% end %><!--but here --> 
<%= render :template => 'layouts/application' %> 
+0

谢谢!这解决了它......我承认我并不完全理解这个布局中的所有代码......但是我会知道<% end %>是错误的地方......我想知道如何/何时做到这一点。谢谢#2:它解决了另一个问题,我试图在StackOverflow中编写! – pitosalas

+0

没有问题。我们都会犯这样的错字。 ;) –

相关问题