Skip to content

Allow nil input with default present #590

@antulik

Description

@antulik

I resisted suggesting this for years, but the issue is keep coming back. I think it's time to fix it.

Problem

I want to provide a default when value is not given e.g. new html form, but allow user to clear value if needed.

integer :num, default: 100
  • Currently it's impossible to allow nil, while providing default
  • default syntax is confusing, as the behavior differs from Rails. I've seen many devs confused by this.

Proposed solution

Separate current default behavior into two options: default and allow_nil.

integer :num, default: 100, allow_nil: true
  • allow_nil is chosen to match rails validations syntax and being self explanatory.
  • no surprises, default is a default, allow_nil allows nil.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions