i have a model called certification_types that i’ve declared as
acts_as_tree. I have a model called certification that belongs_to
:certification_type .
class CertificationController < ApplicationController
…
def summary_list @certifications = Certification.find(:all, :order=>‘date’)
end
end
summary_list.rhtml
<% for certification in @certifications %>
<%= certification.certification_type.parent.id %>
<% end %>
so, the line above (<%=
certification.certification_type.parent.type_description %> ) does not
work; it says The error occured while evaluating nil.type_description.
if i do a debug(certification.certification_type.parent) it shows that i
have a hash of values:
— !ruby/object:CertificationType
attributes:
type_description: Allergy & Immunology
id: “12”
parent_id: “11”
can anyone help me with how to access the parent type_description when
looping through my collection?
<% for certification in @certifications %>
<%= certification.certification_type.parent.id %>
<% end %>
…my guess is that the reason you are getting nil is because there must
be cases in the loop that certification does not have a certification
type - - did you put the
“debug(certification.certification_type.parent)” AFTER the loop? , if
so, you may have gotten the last value of the loop - which does have a
certification type, but other objects in the loop do not, therefore
returning a nil object - -
the best way to see if this is correct or not is to put the debug(…)
inside the loop and see what it returns…
<% for certification in @certifications %>
<%= certification.certification_type.parent.id %>
<% end %>
…my guess is that the reason you are getting nil is because there must
be cases in the loop that certification does not have a certification
type - - did you put the
“debug(certification.certification_type.parent)” AFTER the loop? , if
so, you may have gotten the last value of the loop - which does have a
certification type, but other objects in the loop do not, therefore
returning a nil object - -
the best way to see if this is correct or not is to put the debug(…)
inside the loop and see what it returns…
shai
Shai, I cant believe i missed that! Thank you very much for responding.