Rails 部分显示变量的文本版本

Rails Partial Displays Text Version of Variables

在我的应用程序中,我使用部分模板在我的 workouts#index 页面上呈现来自我的 workouts 模型的多个信息卡。一切正常,但由于某种原因,页面底部生成了一个奇怪的卡片信息文本版本。

这是我的 workouts#index 页面:

<div class="row container full-bg-img-003" style="min-height: 500px">

<div class="row" style="height: 125px"></div>

<% if current_user != nil && current_user.admin? %>
  <div class="text-center"><%= link_to 'Create New Workout', new_workout_path, class:"waves-effect waves-light btn btn-primary" %></div>
<% end %>

<div class="row" style="height: 25px"></div>

  <div class="container col-sm-6 col-sm-push-6">
    <div class="card hoverable" style="padding-bottom: 20px; padding-top: 10px; margin-bottom: 50px; background-color: rgba(255, 255, 255, .85)">
      <div class="container col-sm-12">
        <h4 class="text-center">This is it.</h4>
          <p class="text-center">You've found your way to the inner sanctum of the BurnIt universe.  Here lie all the workouts we have to offer. Use them wisely, young grasshopper.</p>
      </div> <!-- container inside -->
    </div>  <!-- card panel end -->
  </div> <!-- column container -->

<div class="row" style="height: 125px"> </div>

</div> <!-- row -->

<!--Section: Detailed info-->
<section id="sec-details"><div class="container">
  <div class="row">
    <h2 class="text-center">Workouts Database</h2><hr>

    <!--Image Cards Go Here-->
    <%= @workouts.each do |w| %>
    <%= render "workouts/template", workout: w %>
    <% end %>
    <!--Image Cards End Here-->

  </div> <!-- row -->
</div> <!-- container --></section>

这是我的 _template.html.erb 部分:

<div class="container col-sm-6 col-md-4">
  <div class="card hoverable">
      <div class="card-image">
          <div class="view overlay hm-white-slight z-depth-1">
              <%#= link_to workout.workout_img class: "img-responsive" alt: "" %>
              <div class="mask waves-effect"></div>
          </div>
          <h5 class="text-center" style="padding-top: 15px"><%= workout.name %></h5>
      </div>
      <div class="card-content">
          <iframe width="100%" height="200" src="https://www.youtube.com/embed/<%= workout.video %>?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
          <div style="height: 200px">
            <p><strong>Goal: </strong><%= workout.teaser %></p>
            <p><strong>Description: </strong><%= workout.description %></p>
            <p><strong>Workout Difficulty Level: </strong><%= workout.difficulty %></p>
          </div>
      </div>
      <div class="card-action">
          <%= link_to 'Do this one!', workout_path(workout), class: "red-text" %>
      </div>
  </div>
</div>

下面的随机文字出现在页面底部的所有卡片之后:

[#<Workout id: 1, name: "Abs 0002", workout_type: "Abs", teaser: "Abdominal pain begins here...", description: "Since there is no Abs 0001, we begin here. 15 min...", video: "uw9M6VhfW0A", difficulty: 3, trainer: nil, user_id: nil, created_at: "2016-05-17 05:46:46", updated_at: "2016-05-17 05:51:36">, #<Workout id: 2, name: "Abs 0003", workout_type: "Abs", teaser: "Want more abs? You got 'em.", description: "15 minutes, not enough breaks, but hey...there are...", video: "dcEJP2MPvrM", difficulty: 3, trainer: nil, user_id: nil, created_at: "2016-05-18 00:53:14", updated_at: "2016-05-18 00:53:14">, #<Workout id: 3, name: "Abs 0004", workout_type: "Abs", teaser: "", description: "", video: "hTZwbP_lsRk", difficulty: nil, trainer: nil, user_id: nil, created_at: "2016-05-18 01:01:19", updated_at: "2016-05-18 01:01:19">, #<Workout id: 4, name: "Abs 0005", workout_type: "Abs", teaser: "", description: "", video: "2KrzvpHOYwo", difficulty: nil, trainer: nil, user_id: nil, created_at: "2016-05-18 01:01:48", updated_at: "2016-05-18 01:01:48">, #<Workout id: 5, name: "Abs 0006", workout_type: "Abs", teaser: "", description: "", video: "IMwDUfTQ14M", difficulty: nil, trainer: nil, user_id: nil, created_at: "2016-05-18 01:02:15", updated_at: "2016-05-18 01:02:15">, #<Workout id: 6, name: "Abs 0007", workout_type: "Abs", teaser: "", description: "", video: "VLw2gIZdsJE", difficulty: nil, trainer: nil, user_id: nil, created_at: "2016-05-18 01:02:40", updated_at: "2016-05-18 01:02:40">, #<Workout id: 7, name: "Abs 0008", workout_type: "Abs", teaser: "", description: "", video: "PADrEPDBhEA", difficulty: nil, trainer: nil, user_id: nil, created_at: "2016-05-18 01:05:37", updated_at: "2016-05-18 01:05:37">, #<Workout id: 8, name: "Abs 0009", workout_type: "Abs", teaser: "", description: "", video: "qDYnqdv160Y", difficulty: nil, trainer: nil, user_id: nil, created_at: "2016-05-18 01:06:00", updated_at: "2016-05-18 01:06:00">]

谁能告诉我这个随机文本是从哪里来的?

这是因为您在迭代语句中放置了一个 = 符号。这一行<%= @workouts.each do |w| %>应该是这样<% @workouts.each do |w| %>