You check if a project is present
@project.present?
but you don't check if the value of its title
property is set. When title
is nil
, the following concatenation
"- " + @project.title
will fail with the can't convert nil into String
error because you are effectively trying to concatenate
"- " + nil
that are two different types. You must deal with this case explicitly or use nil-to-string casting by using the interpolation
<%= "- #{@project.title}" if @project.present? %>
Moreover, beware of precedences. Embedding if conditions in that way with a print, may lead to obscure bugs caused by evaluation precedence.