为什么我不能渲染 Michael Hartl 的 Rail Tutorial Book 第 11 章练习 1 中的部分?

Why can't I render a partial in Exercise 1 of Chapter 11 of Michael Hartl's Rail Tutorial Book?

我正在尝试完成 Exercise 1, Chapter 11 of Michael Hartl's Rail Tutorial Book,但是当我在浏览器中加载页面时,我没有看到我的局部渲染。

简介是:

Refactor the Home page to use separate partials for the two branches of the if-else statement.

我尝试加载部分的主页模板如下:

<% if logged_in? %>
    <% render 'shared/home_logged_in' %>
<% else %>
    <% render 'shared/home_not_logged_in' %>
<% end %>

我尝试加载的部分之一的示例如下:

<div class="center jumbotron">
  <h1>Welcome to the Sample App</h1>

  <h2>
    This is the home page for the
    <a href="http://www.railstutorial.org/">Ruby on Rails Tutorial</a>
    sample application.
  </h2>

  <%= link_to "Sign up now!", signup_path, class: "btn btn-lg btn-primary" %>
</div>

<%= link_to image_tag("rails.png", alt: "Rails logo"),
            'http://rubyonrails.org/' %>

我的代码在 GitHub here and the changes I have made in an attempt to complete this exercise can be found here.

上可用

我做错了什么?

您正在使用 <% render 'shared/home_logged_in' %> 而不是 <%= render 'shared/home_logged_in' %>。您需要将表达式打印到页面缓冲区中,以便将其包含在响应中。

<% "I am invisible" %>
<%= "I am not" %>