# Newbie: using date-picker

**URL:** <https://www.ruby-forum.com/t/newbie-using-date-picker/59082>\
**Category:** Rails\
**Created:** [April 28, 2006, 2:57pm UTC](https://www.ruby-forum.com/t/newbie-using-date-picker/59082 "2006-04-28T14:57:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![n1c](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3ec8ea/32.png) [@n1c](https://www.ruby-forum.com/u/n1c)\
**Post date:** [April 28, 2006, 2:57pm UTC](https://www.ruby-forum.com/t/newbie-using-date-picker/59082/1 "2006-04-28T14:57:32Z")

</div>

Finally found a nice date chooser script  
([http://projects.exactlyoneturtle.com/date\_picker](http://projects.exactlyoneturtle.com/date_picker)), but am a little  
confused how to implement it.

So I put this where I need the date picker:  
[choose date]

And the field that receives the value is:

But where do I put the following files?  
date\_picker\_helper.rb  
date-picker.css  
date-picker.js

And where do I reference these? I’m using a std \_form.html partial for  
new and edit.

thx  
n.

---

<div class="post-metadata">

**Author:** ![n1c](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3ec8ea/32.png) [@n1c](https://www.ruby-forum.com/u/n1c)\
**Post date:** [April 28, 2006, 3:07pm UTC](https://www.ruby-forum.com/t/newbie-using-date-picker/59082/2 "2006-04-28T15:07:21Z")

</div>

On Fri, 2006-04-28 at 14:57 +0200, Nick C. wrote:

> And the field that receives the value is:
> 
> But where do I put the following files?  
> date\_picker\_helper.rb

* * *

## app/helpers

> date-picker.css

* * *

## public/stylesheets

> date-picker.js

* * *

public/javascripts

> And where do I reference these? I’m using a std \_form.html partial for  
> new and edit.

* * *

the javascript should be referenced in the html header (generally in the  
layout file), the helper should be automatic.

Craig

---

<div class="post-metadata">

**Author:** ![n1c](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3ec8ea/32.png) [@n1c](https://www.ruby-forum.com/u/n1c)\
**Post date:** [April 28, 2006, 3:38pm UTC](https://www.ruby-forum.com/t/newbie-using-date-picker/59082/3 "2006-04-28T15:38:58Z")

</div>

Ok, works perfectly in the page, but how do I get it to insert the value  
into the db. I simply replaced the existing  
\<%= date\_select ‘timelog’, ‘worked\_on’, :class =\> ‘field’ %\>

with

[ choose  
date ]

but I get an error thrown indicating “Mysql::Error: Column ‘worked\_on’  
cannot be null”

These are the request parameters:  
Parameters: {“commit”=\>“Create”, “task”=\>{“percent\_complete”=\>“90”,  
“id”=\>“9”}, “timelog”=\>{“task\_id”=\>“0”, “hours”=\>“1”,  
“comment”=\>“test”}, “worked\_on”=\>“2006-4-26”}

So the date is there. What’s happening??

Then another question - how do I display today’s date on the page (i’ll  
put that instead of the [choose date] link.

thx  
n.

Craig W. wrote:

> On Fri, 2006-04-28 at 14:57 +0200, Nick C. wrote:
> 
> > And the field that receives the value is:
> > 
> > But where do I put the following files?  
> > date\_picker\_helper.rb
> 
> * * *
> 
> ## app/helpers
> 
> > date-picker.css
> 
> * * *
> 
> ## public/stylesheets
> 
> > date-picker.js
> 
> * * *
> 
> public/javascripts
> 
> > And where do I reference these? I’m using a std \_form.html partial for  
> > new and edit.
> 
> * * *
> 
> the javascript should be referenced in the html header (generally in the  
> layout file), the helper should be automatic.
> 
> Craig

---

<div class="post-metadata">

**Author:** ![n1c](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3ec8ea/32.png) [@n1c](https://www.ruby-forum.com/u/n1c)\
**Post date:** [April 28, 2006, 3:43pm UTC](https://www.ruby-forum.com/t/newbie-using-date-picker/59082/4 "2006-04-28T15:43:56Z")

</div>

duh, the field name should have been timelog[worked\_on]. Works perfectly  
now.

Just need to display today’s date now?

thx  
n.

Nick C. wrote:

> Ok, works perfectly in the page, but how do I get it to insert the value  
> into the db. I simply replaced the existing  
> \<%= date\_select ‘timelog’, ‘worked\_on’, :class =\> ‘field’ %\>
> 
> with
> 
> [ choose  
> date ]
> 
> but I get an error thrown indicating “Mysql::Error: Column ‘worked\_on’  
> cannot be null”
> 
> These are the request parameters:  
> Parameters: {“commit”=\>“Create”, “task”=\>{“percent\_complete”=\>“90”,  
> “id”=\>“9”}, “timelog”=\>{“task\_id”=\>“0”, “hours”=\>“1”,  
> “comment”=\>“test”}, “worked\_on”=\>“2006-4-26”}
> 
> So the date is there. What’s happening??
> 
> Then another question - how do I display today’s date on the page (i’ll  
> put that instead of the [choose date] link.
> 
> thx  
> n.

---

<div class="post-metadata">

**Author:** ![n1c](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3ec8ea/32.png) [@n1c](https://www.ruby-forum.com/u/n1c)\
**Post date:** [April 28, 2006, 3:53pm UTC](https://www.ruby-forum.com/t/newbie-using-date-picker/59082/5 "2006-04-28T15:53:09Z")

</div>

Fix that with controller code…assign timelog.worked\_on = Date.today

---

<div class="post-metadata">

**Author:** ![n1c](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/3ec8ea/32.png) [@n1c](https://www.ruby-forum.com/u/n1c)\
**Post date:** [April 28, 2006, 4:13pm UTC](https://www.ruby-forum.com/t/newbie-using-date-picker/59082/6 "2006-04-28T16:13:21Z")

</div>

Craig W. wrote:

> Fix that with controller code…assign timelog.worked\_on = Date.today

Cool, all working nicely now -

In my controller:  
@timelog.worked\_on = Date.today

In my view:  
\<%=Date.today.to\_s(format = :my\_format\_1)%\>

And in environment.rb, to make the rails displayed date format the same  
as the format the date picker uses:  
ActiveSupport::CoreExtensions:📅:Conversions::DATE\_FORMATS.merge!(  
:my\_format\_1 =\> ‘%d %b %Y’  
)

Thanks Craig.

n.
