ruby on rails - Render collection using a partial giving "undefined method for nil:NilClass" -


i'm trying render collection of projects using project partial i'm getting following error:

undefined method `customer' nil:nilclass extracted source (around line #1): 1: <p><%= company_name(@project) %><p> 

the stacktrace is:

app/helpers/projects_helper.rb:4:in `company_name' app/views/projects/_summary.html.erb:1:in app/views/customers/index.html.erb:11:in 

so, index checks projects start with:

<% if @projects.any? %>   <%= render :partial => "projects/summary", :collection => @projects %> <% end %> 

my partial (_summary.html.erb) simply:

<p><%= company_name(@project) %><p> <p><%= summary_description(@project) %><p> 

and projectshelper company_name method is

def company_name(project)   if project.customer.business_name.blank?   ...do stuff... 

if following via rails console, works fine:

projects.first.customer.business_name.blank? 

i'm confused because thought that's rendering collection supposed do. appreciated.

you should change partial to

<p><%= company_name(project) %><p> <p><%= summary_description(project) %><p> 

see rails documentation under "rendering collections".


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -