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: </tr> 18: 19: <% for business in @businesses %> 20: <% for address in @addresses %> 21: 22: <tr> 23: <td><%=h business.address_id %></td> This is my business index.html form: <h1>Listing businesses</h1> <table> <tr> <th>Address</th> <th>Business name</th> <th>Business email</th> <th>Business telephone</th> <th>City</th> </tr> <% for business in @businesses %> <% for address in @addresses %> <tr> <td><%=h business.address_id %></td> <td><%=h business.business_name %></td> <td><%=h business.business_email %></td> <td><%=h business.business_telephone %></td> <td><%=h address.city %></td> <td><%= link_to ''Show'', business %></td> <td><%= link_to ''Edit'', edit_business_path(business) %></td> <td><%= link_to ''Destroy'', business, :confirm => ''Are you sure?'', :method => :delete %></td> </tr> <% end %> <% end %> </table> <br /> <%= 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? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Gary Doades
2010-Feb-18 23:12 UTC
Re: You have a nil object when you didn''t expect it! Error!
On 18/02/2010 11:08 PM, Sam wrote:> 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:</tr> > 18: > 19:<% for business in @businesses %> > 20:<% for address in @addresses %> > 21: > 22:<tr> > 23:<td><%=h business.address_id %></td> > > 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? > >Errm... I guess you''ve missed the fact that you haven''t actually loaded or assigned @addresses in your controller? Cheers, Gary. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Rails ROR
2010-Feb-26 10:36 UTC
Re: You have a nil object when you didn''t expect it! Error!
Hi, You are looping through the addresses this way <% for address in @addresses %> but your controller misses @addresses Please mention that in your controller. Bye!! On Fri, Feb 19, 2010 at 4:38 AM, Sam <samir_odedra-PkbjNfxxIAQqdlJmJB21zg@public.gmane.org> wrote:> 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: </tr> > 18: > 19: <% for business in @businesses %> > 20: <% for address in @addresses %> > 21: > 22: <tr> > 23: <td><%=h business.address_id %></td> > > This is my business index.html form: > > <h1>Listing businesses</h1> > > <table> > <tr> > <th>Address</th> > <th>Business name</th> > <th>Business email</th> > <th>Business telephone</th> > <th>City</th> > </tr> > > <% for business in @businesses %> > <% for address in @addresses %> > > <tr> > <td><%=h business.address_id %></td> > <td><%=h business.business_name %></td> > <td><%=h business.business_email %></td> > <td><%=h business.business_telephone %></td> > <td><%=h address.city %></td> > <td><%= link_to ''Show'', business %></td> > <td><%= link_to ''Edit'', edit_business_path(business) %></td> > <td><%= link_to ''Destroy'', business, :confirm => ''Are you > sure?'', :method => :delete %></td> > </tr> > <% end %> > <% end %> > </table> > > <br /> > > <%= 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? > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
kannav rajeev
2010-Feb-26 10:56 UTC
Re: You have a nil object when you didn''t expect it! Error!
it looks that error coming in yours show.html.erb create a test data fisrt in new.html.erb then GoTo show.html.erb or in show.html.erb Put <%= if @object.nil? %> <% there are No data in records %> <%else%> yours code <% end %> ok if works then tell and if not then must reply.. On Fri, Feb 26, 2010 at 4:06 PM, Rails ROR <developrails-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > You are looping through the addresses this way > <% for address in @addresses %> > but your controller misses @addresses > Please mention that in your controller. > > Bye!! > > On Fri, Feb 19, 2010 at 4:38 AM, Sam <samir_odedra-PkbjNfxxIAQqdlJmJB21zg@public.gmane.org> wrote: > >> 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: </tr> >> 18: >> 19: <% for business in @businesses %> >> 20: <% for address in @addresses %> >> 21: >> 22: <tr> >> 23: <td><%=h business.address_id %></td> >> >> This is my business index.html form: >> >> <h1>Listing businesses</h1> >> >> <table> >> <tr> >> <th>Address</th> >> <th>Business name</th> >> <th>Business email</th> >> <th>Business telephone</th> >> <th>City</th> >> </tr> >> >> <% for business in @businesses %> >> <% for address in @addresses %> >> >> <tr> >> <td><%=h business.address_id %></td> >> <td><%=h business.business_name %></td> >> <td><%=h business.business_email %></td> >> <td><%=h business.business_telephone %></td> >> <td><%=h address.city %></td> >> <td><%= link_to ''Show'', business %></td> >> <td><%= link_to ''Edit'', edit_business_path(business) %></td> >> <td><%= link_to ''Destroy'', business, :confirm => ''Are you >> sure?'', :method => :delete %></td> >> </tr> >> <% end %> >> <% end %> >> </table> >> >> <br /> >> >> <%= 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? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- Thanks: Rajeev sharma -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.