Incorrent rendering of show.html.erb


#1

Hello, can you please help me figure out why my page is displaying the content of @albums like so?

show.html.erb:

<div class="show row">
  <div class="cover col-md-4"> <img src="<%= @album.cover %>"> </div>

  <div class="col-sm-8">
    <h3 class="album-title"> <%= @album.title %> </h3>
    <p class="album-artist"> <% @album.artist %> </p>

    <%= @tracks.each do |track| %>
        <div class="track row">
          <div class="name col-md-8"> <%= track.name %> </div>
          <div class="minutes col-md-4"> <%= track.minutes %> min</div>
        </div>
    <% end %>

  </div>
</div>

albums_controller.rb:

class AlbumsController < ApplicationController
  def index
    @albums = Album.all
  end

  def show
    @album = Album.find(params[:id])
    @tracks = @album.tracks
  end
end

#2

Hi @jan.lesko.skgmail.co,

This is a tricky issue to find :slight_smile: You need to remove the equal sign (=) from your @tracks.eachdo |track| loop:

<% @tracks.each do |track| %>
  <!-- ... -->
<% end %>

#3

Of course = sign will cause @tracks to output its content. Thank you Zystvan.


#4

This topic is solved.