NoMethodError for array in specific view

71 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 best solutions below

0
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>