Newbie: using date-picker


#1

Finally found a nice date chooser script
(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.


#2

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


#3

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


#4

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.


#5

Fix that with controller code…assign timelog.worked_on = Date.today


#6

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::date::Conversions::DATE_FORMATS.merge!(
:my_format_1 => ‘%d %b %Y’
)

Thanks Craig.

n.