6.5 "Did you add the link to the destination?"


#1

i put this code in > app/views/tags/show.html.erb

<% @destinations.each do |d| %>
      <div class="card col-xs-4">
        <%= image_tag d.image %>
        <h2><%= d.name %></h2>
        <p><%= d.description %></p>
        <%= link_to "See more", destination_path(d) %>
      </div>
      <% end %>
    </div>

I have the error Message:"Did you add the link to the destination?"
i don't know what is wrong,


#2

Hi Peheu,

Could you please post a link to the exercise you're on?
I think that the code you posted belongs in app/views/tags/index.html.erb, not show.html.erb, but I'd like to check the exercise :slightly_smiling:


#3

Hi Zystvan,

thanks for your answer

this kind of link?
https://www.codecademy.com/fr/courses/learn-rails/lessons/one-many/exercises/one-many-show-destination

I am quite sure i write it on show.html.er, I restart this exercice 8 times


#4

By using the link i posted
the code works

but still not working in the other tab(the first one)!

thanks for your concern


#5

@peheu Huh, I'm not sure why it works in one browser tab but not in the other.

You shouldn't be looping through all destinations in your show action, though. In the destinations controller, it should have @destination = Destination.find(params[:id]), rather than @destinations = .... Then, in your show view, you should have something like this instead of your current code:

Spoiler

<% image_tag @destination.image %>
<%= @destination.name %>
<%= @destination.description %>
<%= link_to "Edit", edit_destination_path(@destination) %>


#6

I am having the exact same issue and getting very frustrated.


#7

@muna72 Same error doesn't mean same problem, so please create a new topic with your code, the error message you're getting, and a link to the exercise you're on, and we'll help you over there :slightly_smiling:


#8

I am having the same issue as the person above did. Moderator zystvan, in your reply you say, "I think that the code you posted belongs in app/views/tags/index.html.erb, not show.html.erb, but I'd like to check the exercise :slightly_smiling." That is good information to have because the instructions to the exercise tell the programmer to insert the code into "app/views/tags/show.html.erb." See below:

5.

Finally in app/views/tags/show.html.erb below a destination's description, use link_to to add a link to that destination:
◼Use "See more" for the link text
◼By giving the show route a name of "destination", Rails automatically creates a helper method named destination_path. Use destination_path to generate a URL to a specific destination's path.

So is there an error in the instructions? That's probably why everyone is having the same problem.


#9

@bitsolver32602 No, I was mistaken. When I looked at the exercise with the link Peheu provided, it looks like you're both right, show.html.erb is the correct file :slightly_smiling:
I think the problem you all are having is that I think the problem you all are having is that you're looping through all the destinations (@destinations.each do...), when you should have a variable, @destination, that stores the current destination and you show just that, none of the other destinations.

See my post above:


#10

Thank you for the clarification zystvan. I am still stuck on part 5 and losing my mind. I've wasted 3 days stuck on this one exercise and it's completely obstructing my learning. It seems like many other students on this site are struggling with this exercise. I've looked at EVERY forum discussion and tried EVERY code suggested and I'm still stuck.

I've revised my code yet again using the advice your provided in your reply above. It still DOES NOT WORK! Please see my code below. I've highlighted the pertinent code in BOLD. What am I missing??? Please help.




BokenjiKan





<%= @tag.title %>

<div class="cards row">
  <% @destinations.each do |d| %>
  <div class="card col-xs-4">
    <%= image_tag d.image %>
    <h2><%= d.name %></h2>
    <p><%= d.description %></p>
  **  <p><%= link_to "See more" destination_path(@destination) %></p>**
  </div>
  <% end %>
</div>



#11

@bitsolver32602 I'm happy to help, but I'll need you to format your code so it's visible first :wink: (Markdown strips out HTML as a security thing)


#12

The Helper finally gave me the solution code so I was able to understand and reverse engineer the solution to move on in the learning modules. This is the code I was attempting to submit before that the website would not accept as a solution:

<% @destinations.each do |destination| %>
  <div class="card col-xs-4">
    <%= image_tag @destination.image %>
    <h2><%= @destination.name %></h2>
    <p><%= @destination.description %></p>
  **  <p><%= link_to "See more" destination_path(@destination) %></p>**
  </div>
  <% end %>

I am still curious as to why that does not work. Can you please explain?


#13

@bitsolver32602 Backtick (`) != single quote ('):

' single quote
` backtick

see how the backtick "tilts"? Also, you should use triple backticks for multiple lines of code :slightly_smiling:

Your problem - There needs to be a comma (,) between "See more" and destination_path(...), like this:

<p><%= link_to "See more", destination_path(@destination) %></p>

#14

changing |destination| to |d| fixed it. I think there's a lack of information, that's all.


#15