Forum: Ruby on Rails Newbie: using date-picker

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Nick C. (Guest)
on 2006-04-28 16:57
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:
<a     id="_name_link" href="#"
onclick="DatePicker.toggleDatePicker('name')"
       class="demo_link">[ choose date ]</a>
<div   id="_name_calendar" class="date_picker"
style="display:none"></div>

And the field that receives the value is:
<input id="name" name="name" value="" size="10"/></label>

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.
Craig W. (Guest)
on 2006-04-28 17:07
(Received via mailing list)
On Fri, 2006-04-28 at 14:57 +0200, Nick C. wrote:
>
> And the field that receives the value is:
> <input id="name" name="name" value="" size="10"/></label>
>
> 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
Nick C. (Guest)
on 2006-04-28 17:38
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

<a id="_worked_on_link" href="#"
onclick="DatePicker.toggleDatePicker('worked_on')" class="">[ choose
date ]</a>
<div id="_worked_on_calendar" class="date_picker"
style="display:none"></div>
<input type="hidden" id="worked_on" name="worked_on" value=""
size="10"/>

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:
>> <input id="name" name="name" value="" size="10"/></label>
>>
>> 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
Nick C. (Guest)
on 2006-04-28 17:43
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
>
> <a id="_worked_on_link" href="#"
> onclick="DatePicker.toggleDatePicker('worked_on')" class="">[ choose
> date ]</a>
> <div id="_worked_on_calendar" class="date_picker"
> style="display:none"></div>
> <input type="hidden" id="worked_on" name="worked_on" value=""
> size="10"/>
>
> 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. (Guest)
on 2006-04-28 17:53
(Received via mailing list)
Fix that with controller code...assign timelog.worked_on = Date.today
Nick C. (Guest)
on 2006-04-28 18:13
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:
<a id="_timelog[worked_on]_link" href="javascript:;"
onclick="DatePicker.toggleDatePicker('timelog[worked_on]')"
class=""><%=Date.today.to_s(format = :my_format_1)%></a>
<div id="_timelog[worked_on]_calendar" class="date_picker"
style="display:none"></div>
<input type="hidden" id="timelog[worked_on]" name="timelog[worked_on]"
value="<%=@timelog.worked_on%>" size="10"/>

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.
This topic is locked and can not be replied to.