to paint the picture
I currently have a system which lists uses and the Department the user
is assigned to. So my models look something like this.
class User < ActiveRecord::Base
class Department < ActiveRecord::Base
A user may not necessarily have a department which is fine however, when
this user does not have a department this department value will be nil.
When I go to print out this department value I get the following error
You have a nil object when you didn’t expect it!
The error occured while evaluating nil.name
the name value is my department name. What’s the best way to tell rails
to print out nothing if this object is set to nil?
I was thinking of setting up a helper method. But I’m not sure that
that is the best thing to do.
Thanks in advance for any help.