1

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...

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

<!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:

<!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>

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

2
  • layout file is named as application.htmm.erb or application.html.erb ? In any case I suggest you correct the typo in the question is its correct in your application. Commented Oct 24, 2012 at 13:02
  • did you check Which view actually adding the contents above the <doctype? Commented Oct 24, 2012 at 13:04

1 Answer 1

1

You should move the end in the content_for loop down like this 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' %>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! That solved it... I admit I don't quite understand all the code in this layout ... but I would have known that the <% end %> was in the wrong place... I wonder how/when I did that. Thanks#2: it solved another problem which I was trying to write up in StackOverflow!
No prob. We all make typos like this. ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.