Show a tag 5/9

Stuck again. It says there"Then in the Tags controller, add the show action:" …And I did exactly what was asked, pasted the code into the tags controller file. But no matter where I try to fill in the method ‘destinations’ it keeps saying that its undefined. Here’s the code:

class TagsController < ApplicationController
  def index
    @tags = Tag.all
    end
  def show 
      @tag = Tag.find(params[:id]) 
      @destinations = @tag.destinations 
  end
end

Hi Daniel,

The code you posted works fine for me. Would you mind posting the code you have in app/views/tags/show.html.erb, please?
Thanks! :slight_smile:

sure. its

<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">  </h2>

    <div class="cards row">
		

      <!--
      To do: Loop through destinations and display each one with this HTML
      <div class="card col-xs-4">
        destination's image goes here
        <h2> destination's name goes here </h2>
        <p> destination's description goes here </p>
      </div>
      -->

    </div>

  </div>
</div>

there is more :wink:

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

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

    <div class="cards row">
    

    </div>

  </div>
</div>

for some reason it won’t show everything. if you want i can also make a screenshot

@kosmotakis Thanks, but no, screenshots don’t let me copy/paste the code out of them to test it :slight_smile:

See here for how to make code visible:

tried that. doesn’t work always on my mac. sometimes works sometimes just doesnt. going to try again later

@kosmotakis Weird :confused:
No worries, though :slight_smile: I’ll edit your posts for you and take a look to see if I can find the problem :slight_smile:

@kosmotakis Well, your index and show code isn’t complete, but I don’t think that’s really your problem.
Could you post the code in config/routes.rb please? (almost definitely the last file I’ll need :smile:)

Here it is

´Rails.application.routes.draw do
get ‘/tags/:id’ => ‘tags#show’, as: :tag
get ‘/tags’ => 'tags#index’´

@kosmotakis Hm, not sure why you’re getting anything about “undefined” stuff :confused:
Maybe try again later?

:slightly_smiling: thats what I was thinking. I will let you know if there is a different error at some point :wink:

1 Like

Hey man. Want to know what the problem was? Like many times it was a missing space:smile:. this is the code that worked `class TagsController < ApplicationController
def index
@tags = Tag.all
end

def show 
@tag = Tag.find(params[:id]) 
@destinations = @tag.destinations 
end

end`

1 Like

@kosmotakis Great! I’m glad you were able to find the problem :slight_smile:
Good luck with the rest of the course!

2 posts were split to a new topic: Stuck on “Show a Tag” 5/9