# Request advice on best/usable field default

**URL:** <https://www.ruby-forum.com/t/request-advice-on-best-usable-field-default/188353>\
**Category:** Rails\
**Created:** [May 10, 2010, 6:14pm UTC](https://www.ruby-forum.com/t/request-advice-on-best-usable-field-default/188353 "2010-05-10T18:14:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [May 10, 2010, 6:14pm UTC](https://www.ruby-forum.com/t/request-advice-on-best-usable-field-default/188353/1 "2010-05-10T18:14:19Z")

</div>

Hi all,  
I am creating a bash.org-like. Basically: just store and retrieve quotes  
that people enter. I would like the user to have the option of entering  
a few fields, among which are a date a and location field.  
What do you think is the best default to use for these fields? nil, or  
today’s date (or January 1st, year 1), or an empty string?  
It may be possible later to search or sort using these fields, which is  
why I am asking how you would do this. I may have not searched well, but  
I didn’t find anything on the web about this.

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [May 10, 2010, 6:35pm UTC](https://www.ruby-forum.com/t/request-advice-on-best-usable-field-default/188353/2 "2010-05-10T18:35:02Z")

</div>

On May 10, 2010, at 9:14 AM, Aldric G. wrote:

> Hi all,  
> I am creating a bash.org-like. Basically: just store and retrieve quotes  
> that people enter. I would like the user to have the option of entering  
> a few fields, among which are a date a and location field.  
> What do you think is the best default to use for these fields? nil, or  
> today’s date (or January 1st, year 1), or an empty string?  
> It may be possible later to search or sort using these fields, which is  
> why I am asking how you would do this. I may have not searched well, but  
> I didn’t find anything on the web about this.

If it were me… I’d default the date to today, and leave location  
blank. Defaulting the date to today makes some sense as 6 months from  
now if I’m searching I’ll remember “well, i entered it about 6 months  
ago so search around then”.

That doesn’t work with location so leave it blank.

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [May 10, 2010, 6:38pm UTC](https://www.ruby-forum.com/t/request-advice-on-best-usable-field-default/188353/3 "2010-05-10T18:38:20Z")

</div>

Aldric G. wrote:

> Hi all,  
> I am creating a bash.org-like. Basically: just store and retrieve quotes  
> that people enter. I would like the user to have the option of entering  
> a few fields, among which are a date a and location field.  
> What do you think is the best default to use for these fields? nil, or  
> today’s date (or January 1st, year 1), or an empty string?

Depends on your use case. If you think that most of the time, the user  
will want to date things today, then use that as a default. 1/1/1 is  
probably not a sensible default in most cases, and an empty string  
certainly wouldn’t be sensible for a date field (which shouldn’t contain  
a string). In most cases, then, for date, I’d probably use either nil  
or a reasonable date (such as today).

For location…can you use Google’s currentLocation or some such to get  
the client’s location if possible? That would be a great default for  
many applications. If not, nil is good here too.

> It may be possible later to search or sort using these fields, which is  
> why I am asking how you would do this. I may have not searched well, but  
> I didn’t find anything on the web about this.
> 
> Thanks 🙂

Note that this is really a general UI and database design question. You  
will probably come up with the best solutions if you think in those  
directions.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [May 10, 2010, 7:38pm UTC](https://www.ruby-forum.com/t/request-advice-on-best-usable-field-default/188353/4 "2010-05-10T19:38:16Z")

</div>

Philip H. wrote:

> If it were me… I’d default the date to today, and leave location  
> blank. Defaulting the date to today makes some sense as 6 months from  
> now if I’m searching I’ll remember “well, i entered it about 6 months  
> ago so search around then”.

So… How should I tell Rails that “This field’s default date is always  
today” ? Can I do this within the migration, or should I set the field  
upon form generation?

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [May 10, 2010, 8:55pm UTC](https://www.ruby-forum.com/t/request-advice-on-best-usable-field-default/188353/5 "2010-05-10T20:55:30Z")

</div>

Aldric G. wrote:

> Philip H. wrote:
> 
> > If it were me… I’d default the date to today, and leave location  
> > blank. Defaulting the date to today makes some sense as 6 months from  
> > now if I’m searching I’ll remember “well, i entered it about 6 months  
> > ago so search around then”.
> 
> So… How should I tell Rails that “This field’s default date is always  
> today” ? Can I do this within the migration, or should I set the field  
> upon form generation?

Well, if it were a constant default value, I would say that you should  
set it in the DB, not in Rails. Since “today” is a computed default  
value, check whether your DB will do this. If it will, you’re home  
free.

If not…well, you’re using form\_for, right? That means you always have  
an object that your form is reading from, right? That means you can  
initialize defaults in the constructor.

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [May 10, 2010, 8:55pm UTC](https://www.ruby-forum.com/t/request-advice-on-best-usable-field-default/188353/6 "2010-05-10T20:55:56Z")

</div>

Aldric G. wrote:

> Philip H. wrote:
> 
> > If it were me… I’d default the date to today, and leave location  
> > blank. Defaulting the date to today makes some sense as 6 months from  
> > now if I’m searching I’ll remember “well, i entered it about 6 months  
> > ago so search around then”.
> 
> So… How should I tell Rails that “This field’s default date is always  
> today” ? Can I do this within the migration, or should I set the field  
> upon form generation?

Well, if it were a constant default value, I would say that you should  
set it in the DB, not in Rails. Since “today” is a computed default  
value, check whether your DB will do this. If it will, you’re home  
free.

If not…well, you’re using form\_for, right? That means you always have  
an object that your form is reading from, right? That means you can  
initialize defaults in the constructor.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [May 10, 2010, 7:27pm UTC](https://www.ruby-forum.com/t/request-advice-on-best-usable-field-default/188353/7 "2010-05-10T19:27:27Z")

</div>

Marnen Laibow-Koser wrote:

> Depends on your use case. If you think that most of the time, the user  
> will want to date things today, then use that as a default.
> 
> For location…can you use Google’s currentLocation or some such to get  
> the client’s location if possible? That would be a great default for  
> many applications. If not, nil is good here too.

Phillip, Marnen,

Thanks. Those suggestions make a lot of sense 🙂

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [May 10, 2010, 10:03pm UTC](https://www.ruby-forum.com/t/request-advice-on-best-usable-field-default/188353/8 "2010-05-10T22:03:58Z")

</div>

Marnen Laibow-Koser wrote:

> If not…well, you’re using form\_for, right? That means you always have  
> an object that your form is reading from, right? That means you can  
> initialize defaults in the constructor.

Duh. That’s the clean way to do it, of course. Thank you, Marnen 🙂
