You could test whether the params are present like so: params[:param_name].present?
The present?
method (inverse of blank?
) tests for empty?
but also returns false for whitespace so that ''
, ' '
, nil
, []
, and {}
are all false.
An improvement on this would be to use the presence
method. Then you could do this directly in your controller method without the need for callbacks:
fqdn = params[:fqdn].presence || MyRandomNameGenerator.generate