Associations I 5.Show a tag (Part 3)


#1

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> <%= destination.name %> </h2>
        <p> <%= destination.description %> </p>
      </div>
      <% end %>

    </div>

  </div>
</div>

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

<%= destination.name %>

?

#2

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.


#3

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><%= t.name %></h2> 
   <p><%=  t.description %></p>  
   </div>
   <% end %>
   </div>

#4

AH i see! thank you! :slight_smile:


#5

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


#6

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.


#7

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


#8

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