There's not nil:NilClass
exception thrown by default.
a
or b
or c
may be nil, so for a one line statement you can do:
# require this to use present?, not needed with rails
require 'active_support/all'
a.present? ? (a.b.present? ? (a.b.c.present? ? a.b.c : 'Fill here') : 'Fill here') : 'Fill here'
(And this is ternary expression, not exactly an if statement)
But this is ugly, although you can remove parts of the expression if you are sure that a
or a.b
is never nil
.
I used present?
over blank?
to keep the same order as your expression. The ternary operator evaluates the first expression if the condition is true, so this may be your error.