We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
We usually do:
if input = nil value = input || 'default' => value = 'default'
But if input is not nil, it is empty string: input = ''
if input = '' value = input || 'default' => value = ''
How can we set default value for empty string ?
value = input.present? ? input : 'default'
input = '' value = input.presence || "default" => "default" input = 'value' value = input.presence || "default" => "value" input = nil value = input.presence || "default" => "default"
^_^
The text was updated successfully, but these errors were encountered:
No branches or pull requests
We usually do:
But if input is not nil, it is empty string: input = ''
How can we set default value for empty string ?
Rails adds presence method to all object that does exactly what you want
See below to use presence:
^_^
The text was updated successfully, but these errors were encountered: