Hello everyone,
I’m on step 3 of 5/9 - Associations I, and I’m getting this error: undefined method `image’ for #Array:0x00000005166480
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!