Rails在

时间:2022-11-12 08:19:43

I can't understand how this happens. Show source on my page starts like this -- yes that is the very start of the html, and I have double checked it in Chrome and Safari...

我无法理解这是怎么发生的。在我的页面上显示源代码就像这样开始 - 是的,这是html的开头,我在Chrome和Safari中对它进行了双重检查......

        </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" />

Yet my application.html.erb starts like this:

然而我的application.html.erb开头是这样的:

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

I can't think of scenarios that would cause this...

我想不出会导致这种情况的情景......

Here are some more details, from log:

以下是日志中的更多详细信息:

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

And here are the relevant views:

以下是相关意见:

application.html.erb:

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:

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:

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>

I wonder if I am messing something up with my content_for statements?

我想知道我是否在使用content_for语句搞砸了什么?

1 个解决方案

#1


1  

You should move the end in the content_for loop down like this reptabs.html.erb:

您应该将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' %>

#1


1  

You should move the end in the content_for loop down like this reptabs.html.erb:

您应该将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' %>