cherye
August 31, 2016, 10:58am
#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 %> ?
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><%= t.name %></h2>
<p><%= t.description %></p>
</div>
<% end %>
</div>
cherye
August 31, 2016, 12:00pm
#5
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.
cherye
August 31, 2016, 12:40pm
#7
hmmm… I recall @something means an instance of variable, does it have anything to do with that?
system
closed
September 7, 2016, 12:40pm
#8
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.