# Radio buttons?

**URL:** <https://www.ruby-forum.com/t/radio-buttons/165576>\
**Category:** Rails\
**Created:** [April 15, 2009, 1:05pm UTC](https://www.ruby-forum.com/t/radio-buttons/165576 "2009-04-15T13:05:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [April 15, 2009, 1:05pm UTC](https://www.ruby-forum.com/t/radio-buttons/165576/1 "2009-04-15T13:05:19Z")

</div>

if i got a couple of radio buttons on my form that i want to use a  
published\_at field rather than a boolean field how would i go about  
this? I know that if i’m using a boolean i can do the following.

\<%= f.radio\_button :published\_at, true %\> Yes  
\<%= f.radio\_button :published\_at, false %\> No

but what would i have to change to use the datetime field?

many thanks in advance guys,

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [April 15, 2009, 1:31pm UTC](https://www.ruby-forum.com/t/radio-buttons/165576/2 "2009-04-15T13:31:06Z")

</div>

On 15 Apr 2009, at 12:05, Dave S. wrote:

> if i got a couple of radio buttons on my form that i want to use a  
> published\_at field rather than a boolean field how would i go about  
> this? I know that if i’m using a boolean i can do the following.
> 
> \<%= f.radio\_button :published\_at, true %\> Yes  
> \<%= f.radio\_button :published\_at, false %\> No
> 
> but what would i have to change to use the datetime field?

Are you expecting people to enter a date or to choose between one of  
several dates ?

Fred

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [April 15, 2009, 3:06pm UTC](https://www.ruby-forum.com/t/radio-buttons/165576/3 "2009-04-15T15:06:54Z")

</div>

On 15 Apr 2009, at 12:54, Dave S. wrote:

> > > \<%= f.radio\_button :published\_at, false %\> No  
> > > i was actually hoping for when they check the yes option is puts the  
> > > current time in the field. and when they click no it is removed.

Ah, so that’s more than a radio button. it’s some radio buttons + your  
favourite date input method, together with a chunk of javascript that  
does stuff to those input controls.  
The radio\_button would be for a separate attribute (which might not  
even be a real one) to published\_at

Fred

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [April 15, 2009, 1:54pm UTC](https://www.ruby-forum.com/t/radio-buttons/165576/4 "2009-04-15T13:54:30Z")

</div>

Frederick C. wrote:

> On 15 Apr 2009, at 12:05, Dave S. wrote:
> 
> > if i got a couple of radio buttons on my form that i want to use a  
> > published\_at field rather than a boolean field how would i go about  
> > this? I know that if i’m using a boolean i can do the following.
> > 
> > \<%= f.radio\_button :published\_at, true %\> Yes  
> > \<%= f.radio\_button :published\_at, false %\> No
> > 
> > but what would i have to change to use the datetime field?
> 
> Are you expecting people to enter a date or to choose between one of  
> several dates ?
> 
> Fred

Hi,

i was actually hoping for when they check the yes option is puts the  
current time in the field. and when they click no it is removed.

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [April 15, 2009, 4:52pm UTC](https://www.ruby-forum.com/t/radio-buttons/165576/5 "2009-04-15T16:52:18Z")

</div>

On 15 Apr 2009, at 15:05, Dave S. wrote:

> > favourite date input method, together with a chunk of javascript that  
> > does stuff to those input controls.  
> > The radio\_button would be for a separate attribute (which might not  
> > even be a real one) to published\_at
> > 
> > Fred
> 
> ahh ok! thanks, is that much more difficult to implement? i have  
> searched for examples online and in my rails books but cannot find  
> anything.

Not massively difficult. Not a rails issue at all though - get out  
your html and javascript books to find out about event handling and so  
on.

Fred

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [April 15, 2009, 4:05pm UTC](https://www.ruby-forum.com/t/radio-buttons/165576/6 "2009-04-15T16:05:46Z")

</div>

Frederick C. wrote:

> On 15 Apr 2009, at 12:54, Dave S. wrote:
> 
> > > > \<%= f.radio\_button :published\_at, false %\> No  
> > > > i was actually hoping for when they check the yes option is puts the  
> > > > current time in the field. and when they click no it is removed.
> 
> Ah, so that’s more than a radio button. it’s some radio buttons + your  
> favourite date input method, together with a chunk of javascript that  
> does stuff to those input controls.  
> The radio\_button would be for a separate attribute (which might not  
> even be a real one) to published\_at
> 
> Fred

ahh ok! thanks, is that much more difficult to implement? i have  
searched for examples online and in my rails books but cannot find  
anything.
