Show a tag 5/9


#1

Hello everyone,

I'm on step 3 of 5/9 - Associations I, and I'm getting this error: undefined method `image' for #

This is my code for app/views/taghs/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">  </h2>

    <h2><%= @tag.title %> </h2>
    <div class="cards row"> 
			<% @destinations.each do |d| %>
      <div class="card col-xs-4">
        <%= @destinations.image %>
        <h2><%= @destinations.name %> </h2>
        <p> <%= @destinations.description %></p>
      </div>
        <%end%>
      <!--
      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>

This is my code for the Tags migration file:

class CreateTags < ActiveRecord::Migration
  def change
    create_table :tags do |t|
			t.string :title
      t.string :image
      t.timestamps
    end
  end
end

This is my code for the Destinations migration file:

class CreateDestinations < ActiveRecord::Migration
  def change
    create_table :destinations do |t|
			t.string :name
      t.string :image
      t.string :description
      t.references :tag
      t.timestamps
    end
  end
end

This is my routes.rb:

Rails.application.routes.draw do

	get '/tags' => 'tags#index'
  get '/tags/:id' => 'tags#show', as: :tag
end

This is my Tags Controller:

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

Please help! Thanks!


#2

Error:

undefined method `image' for #<Array:0x00000005166480>

#3

The iterator is defined as |d|, as in,

d.image
d.name
d.description

Try this fix and see if it solves your problem. Let us know if it doesn't. If you still need help, please post a link to this exercise.


#4

Of course! Thank you so much!


#7

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