would anybody tell me what’s going on? my code seems right!
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.
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
@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
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.