Rails Associations I 6-4


#1

would anybody tell me what's going on? my code seems right!


#2

Hi @simon_peng,

That error message means that there's no @destinations variable. Did you create it in your Destinations controller's show action?

If that doesn't fix it, then please post a link to the exercise you're on and copy/paste in your full code.


#3

https://www.codecademy.com/en/courses/learn-rails/lessons/one-many/exercises/one-many-show-destination?action=resume

in my destinations_controller

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

in my app/views/destinations/show.html.erb

<% @destinations.each do |destination| %>
        <img src="<%= destination.image %>">
        <h2>
          <%= destination.name %>
        </h2>
        
        <p>
          <%= destination.description %>
        </p>
        
        <% end %>

still get error messages like this : undefined method `each' for nil:NilClass


#4

@simon_peng Make your variable be @destination (singular) instead of @destinations (plural), and replace endhere with just end.

Then, in your HTML file, remove the loop and add an At sign (@) in front of each destination, so that you're doing this for example:

<h2>
  <%= @destination.name %>
</h2>

instead of what you have right now, <%= destination.name %>.

I hope this helps, please let me know if you need any more help :slight_smile:


#5

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