Hi, I’ve created a business form and an address form using scaffolding
and I am trying to get the business form to display some information
from the address form, but I keep getting an “You have a nil object
when you didn’t expect it! You might have expected an instance of
Array. The error occurred while evaluating nil.each” error.
17:
18:
19: <% for business in @businesses %>
20: <% for address in @addresses %>
21:
22:
23:
This is my business index.html form:
Listing businesses
Address | Business name | Business email | Business telephone | City | |||
---|---|---|---|---|---|---|---|
<%=h business.address_id %> | <%=h business.business_name %> | <%=h business.business_email %> | <%=h business.business_telephone %> | <%=h address.city %> | <%= link_to 'Show', business %> | <%= link_to 'Edit', edit_business_path(business) %> | <%= link_to 'Destroy', business, :confirm => 'Are you sure?', :method => :delete %> |
<%= link_to ‘New business’, new_business_path %>
This is my business controller form:
def index
@businesses = Business.search(params[:search])
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @businesses }
end
end
def show
@business = Business.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @business }
end
end
What have I missed?