Liz Liz - 6 months ago 7
HTML Question

Rails Partial Displays Text Version of Variables

In my app I'm using a partial template to render multiple information cards from my

workouts
model on my
workouts#index
page. Everything is working perfectly, but for some reason there is a weird text version of the information on the cards generating on the bottom of the page.

Here's my
workouts#index
page:

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


And here's my
_template.html.erb
partial:

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


The random text below is appearing after all the cards at the bottom of the page:

[#<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">]


Can anyone tell me where this random text is coming from?

Answer

It's because in you iteration statement you put an = sign. This line <%= @workouts.each do |w| %> should be like this <% @workouts.each do |w| %>