Associations I 5.Show a tag (Part 3)

The instructions:

In app/views/tags/show.html.erb inside the

element, display a tag’s title.

Then in

, iterate through each destination in the @destinations array and display its image, name, and description.

My code:

<div class="tag">
  <div class="container">
    <h2 class="tag-title"> <%= tag.title %> </h2>

    <div class="cards row">
<% @destinations.each do |destination| %>
      <div class="card col-xs-4">
        <%= destination.image %>
        <h2> <%= %> </h2>
        <p> <%= destination.description %> </p>
      <% end %>



I’m not sure what’s wrong with it? Also, why do we need an equal sign in the front, example:

<%= %>


I’m also having trouble with this exercise, however, I can help you on the equals sign. That is used when the code you’re typing actually has to render something (name, title, image) in the browser. When you just want to run code (like with the iteration) then you leave out the equals sign. When you want to display something, you use the equals sign.

Here is the answer:

 <h2 class="tag-title"> <%= @tag.title %> </h2>

 <div class="cards row">
     <% @destinations.each do |t| %>
   <div class="card col-xs-4">
     <%=t.image %>
   <h2><%= %></h2> 
   <p><%=  t.description %></p>  
   <% end %>

AH i see! thank you! :slight_smile:

thank you! I omitted the @ in @tag.title. why is it important that i have the @?

I am not sure but i think we need the “@” because we talk about arrays.
That mean that we need the tag array and with “@” we get it.

hmmm… I recall @something means an instance of variable, does it have anything to do with that?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.