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


#1

Can't figure out why this does not work

show.html.erb

<div class="header">
  <div class="container">
    <img src="http://s3.amazonaws.com/codecademy-content/courses/learn-rails/img/logo-1tm.svg" width="80">
    <h1>BokenjiKan</h1>
  </div>
</div>

<div class="destination">
  <div class="container">
    <div class="row">
      <div class="col-xs-12">
        	<img class='destination' <%= image_tag @destination.image =%> />
        	<h2 class='destination'><%= @destination.name =%></h2>
        	<p class='destination'><%= @destination.description =%></p>
        	<%= link_to "See more", destination_path(@destination) %>
      </div>
    </div>
  </div>
</div>

destinations_controller.rb

class DestinationsController < ApplicationController
  def show
    @destinations = Destination.find(params[:id])
end

routes.rb

Rails.application.routes.draw do
	get "tags" => "tags#index"
  get "tags/:id" => "tags#show", as: :tag
  
  get "destinations/:id" => "destinations#show", as: :destination
end

Error is in the title. Thanks for the help,

Joe


#2

Hi @joefedden,

Your code looks fine to me except that your destinations_controller.rb file is missing a second end. Could you please post a link to the exercise you're on?


#3

I just added the second end to the destination_controller.rb and no luck.

Here's the link to the exercise: https://www.codecademy.com/en/courses/learn-rails/lessons/one-many/exercises/one-many-show-destination?action=resume


#4

@joefedden You should only have an equal sign (=) at the beginning of a Ruby tag that gets shown, like this:

<%= @destination.name %>
                 <!-- ↑ no `=` here -->

:slight_smile:


#5

Alright I changed it to this:

<img class='destination' <%= image_tag @destination.image %> />
<h2 class='destination'><%= @destination.name %></h2>
<p class='destination'><%= @destination.description %></p>
<%= link_to "See more", destination_path(@destination) %>

Still no luck unfortunately, same error message. Any other suggestions?


#6

I'm experiencing the same issue:

<%= image_tag @destination.image %>
<%= @destination.name %>
<%= @destination.description %>
<%= link_to "See more", destination_path(@destination) %>

From everything I've read, this should work...


#7

I JUST got it to work by removing the @destination argument from the link:

<%= link_to "See more", destination_path %>

#8

@joefedden Better :slight_smile:

Now,

  1. The class attribute isn't needed on any of those elements
  2. Remove the <img ... /> around the Ruby tag for an image - <%= image_tag ... %> will automatically output it's own <img> tag, so by having it nested like that, the output to the browser looks like this:

<img <img src="..."> />

which makes no since to it, so it'll just ignore that image.


@psyonix That might pass you, but it's incorrect code and will through an error in the browser. destination_path needs a parameter to work properly. Your original code for the link was correct :slight_smile:


#9

Ok I changed it to this:

<%= image_tag @destination.image %>
<h2 class='destination'><%= @destination.name %></h2>
<p class='destination'><%= @destination.description %></p>
<%= link_to "See more", destination_path(@destination) %>

It is still throwing me the link error though.


#10

Sorry, I just removed the class attributes:

<%= image_tag @destination.image %>
<h2><%= @destination.name %></h2>
<p><%= @destination.description %></p>
<%= link_to "See more", destination_path(@destination) %>

Still getting the error though


#11

That's odd. So it would have to be a bug of some kind? I figured it would need the param but for the life of me it wouldn't work.


#12

@joefedden That code looks fine to me, could I see the rest of your code in app/views/tags/show.html.erb?


@psyonix Yeah, it seems like a bug in how they check code to me :confused:


#13

Here is app/views/tags/show.html.erb:

<div class="header">
  <div class="container">
    <img src="http://s3.amazonaws.com/codecademy-content/courses/learn-rails/img/logo-1tm.svg" width="80">
    <h1>BokenjiKan</h1>
  </div>
</div>

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

Thanks for all your help btw!


#14

@joefedden It looks to me like you're missing a </div> at the end of your file there, so try adding that, as well as applying all of the changes I've suggested you make in my previous posts.


#15

I tried adding one with no luck. I also fixed the other issues from before to no avail.

Any other options?


#16

@joefedden

You need to use the link_to inside the app/views/tags/show.html.erb not in the app/views/destinations/show.html.erb

so you can use this

<%= link_to "See more", destination_path(d) %>

bellow to destinations description:

<%= d.description %>

hope this helps you!


#17

@joefedden I don't know how I got so confused, but @pyblaster47487 is right, and I'm sorry for all of the confusion I've caused while sending you the wrong direction.

Here's what my code for the loop looks like, if you need a reference for what it should look like:

:warning: Spoiler! (click to view)

<% @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 %>

#18

Finally passed me! Thanks to all you for the help!


#19

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