NoMethodError for array in specific view

55 views Asked by At

Here is the error I am receiving

    NoMethodError in Restaurants#index


undefined method `address' for nil:NilClass

When I try to add :

Address: <%= @restaurant.address %>

(note that this <%[email protected]%> works in restaurants/Show.html.erb

to my array :

     <%= div_for(@restaurants, :class => "container") do |restaurant| %>
    <div class="row carousel-row">
1

There are 1 answers

0
Libby On

You should remove the @ symbol. Your variable in the for-loop is restaurant so you can access the address with

<p>Address: <%= restaurant.address %></p>