ruby on rails - undefined method `name' for nil:NilClass -
i have problem on te line
<td><%= h box.manufacturer.name %></td> of
<% @boxes.each |box| %> <tr> <td><%= h box.manufacturer.name %></td> <td><%= h box.model %></td> <td><%= link_to 'mostrar', :action => 'show', :id => box %></td> <td><%= link_to 'editar', :action => 'edit', :id => box %></td> <td><%= button_to 'eliminar', { :action => 'destroy', :id => box }, :confirm => "are sure want delete box #{box.model}?" %></td> manufacturers table field called name,its supposed object manufacturer has member called name ,isn it?
it's quite clear 1 of box records doesn't have associated manufacturer. if it's acceptable, can use object#try method, this:
<%= box.manufacturer.try(:name) %> if it's not, should think of adding proper validation box model:
validates_presence_of :manufacturer i didn't use h helper because in rails >= 3.0 (which use) untrusted content escaped automatically.
Comments
Post a Comment