I'm trying to display the school name for the users. When they sign up users can select a school which they belong to (not everyone does though so sometimes this column is left blank).
At the moment I have:
if user.is_a? Student
%td= user.school
end
which finds the schools that the students belong to, but displays it as the activerecord record. Each of the schools has a name and if I select a single student and do: @student.school.name
it gives me the name of the school with no issues.
However if I do:
if user.is_a? Student
%td= user.school.name
end
It keeps throwing up undefined method
name' for nil:NilClass`
I am pretty sure this is because some of the students don't have a school. I have tried to add this to the if statement but I can't seem to make it work. I tried variations of:
if user.is_a? Student && !user.school.blank?
with .any?
, .empty?
but none of them work, they just so no method .blank?
etc.
Any help please?