# Ajax Date Selector or similar?

**URL:** <https://www.ruby-forum.com/t/ajax-date-selector-or-similar/171345>\
**Category:** Rails\
**Created:** [June 30, 2009, 9:58pm UTC](https://www.ruby-forum.com/t/ajax-date-selector-or-similar/171345 "2009-06-30T21:58:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [June 30, 2009, 9:58pm UTC](https://www.ruby-forum.com/t/ajax-date-selector-or-similar/171345/1 "2009-06-30T21:58:20Z")

</div>

I’ve been trying to find a date picker that works really well with  
Rails. I’ve looked into the following thus far:

jMaki Widget jQuery.datepicker  
jRails jQuery.datepicker

However, none of these provide any information on how to use them with  
Rails. I’ve scrounged the web for tutorials or any information about  
jQuery but most are either very out of date, or don’t have any substance  
that I can work through.

Can anyone recommend something that will allow me to do the following:

User visits “x” page that contains a pre-populated table view.  
User clicks on “y” button/widget/etc.  
User selects a date (either from a drop down or a calendar widget)  
Date is sent to a find/search parameter.  
Data for the pre-populated table view is refreshed to show the new  
criteria based on date.

I would believe that people who use rails would be using many types of  
datepickers/selectors/etc. I’m surprised to see that there is very  
little documentation about this area. Rails and ajax go hand in hand…

Maybe my google is broke…

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [June 30, 2009, 10:19pm UTC](https://www.ruby-forum.com/t/ajax-date-selector-or-similar/171345/2 "2009-06-30T22:19:49Z")

</div>

Ã„lphÃ¤ BlÃ¼Ã« wrote:

> I’ve been trying to find a date picker that works really well with  
> Rails. I’ve looked into the following thus far:
> 
> jMaki Widget jQuery.datepicker  
> jRails jQuery.datepicker
> 
> However, none of these provide any information on how to use them with  
> Rails.

Every JS date picker I’m aware of populates a form field. Just submit  
the form containing that field, and you’ll get the data you want.  
There’s nothing magical about it.

[…]

> I’m surprised to see that there is very  
> little documentation about this area.

There’s really nothing to document, provided you understand how forms  
are submitted in Rails.

> Rails and ajax go hand in hand…

Not really. Rails provides a few canned Ajax helpers (that probably  
should be avoided in any case – or used with lowpro – since they  
generate inline JS), and deals nicely with XML and JSON requests, but  
that’s about it. (I’ve done complex Ajax development, but never with  
Rails.)

> Maybe my google is broke…

No, I think you’re looking for an explanation of something that’s too  
trivial for most people to write about.

## Best,

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

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [June 30, 2009, 11:12pm UTC](https://www.ruby-forum.com/t/ajax-date-selector-or-similar/171345/3 "2009-06-30T23:12:26Z")

</div>

Hi Marnen,

Yeah I suppose I should have been more precise as to what I was trying  
to find. I did find something that will work with what I’m after:

[http://agilewebdevelopment.com/plugins/calendariffic\_0\_1\_0](http://agilewebdevelopment.com/plugins/calendariffic_0_1_0)

I wanted something that worked as a widget that had a nice theme, was  
easy to style, and easy to date convert. Using this I can do the  
following:

\<%= calendariffic\_input(false, :compiled\_on, ‘calendariffic/date.png’,  
‘search\_cal’, ‘%Y-%m-%d’, @todays\_date, {}, {:class =\> ‘borderless’})  
%\>

Pretty easy method call and the documentation in the file matches  
something I can read pretty easily. I changed the dateformat, the  
name/id, and can pass this along to my named\_scope to generate the date.

Now I just have to figure out whether I need to use an actual submit  
button or whether I can find something that works like an OnChange or an  
observer method. I’d like it so that when someone presses the calendar  
widget and selects the date, a notifier method changes the data…

I’ll look into it…

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [July 1, 2009, 12:03am UTC](https://www.ruby-forum.com/t/ajax-date-selector-or-similar/171345/4 "2009-07-01T00:03:18Z")

</div>

Okay I got it to work with the form submit and everything is searching  
and submitting fine.

However, I have a question regarding the url links and submits and  
default behavior. This might be an easy question for most so I  
apologize in advance.

I have a main table in my index along with 2 search forms.

One search form basically allows a search of team names within the  
database.  
One search form allows a search for all data within distinct specific  
date ranges.  
The default table view shows all data compiled for the current week.

So, using the default table view if I go to my site the url is going to  
be something like:

[localhost.com/page](http://localhost.com/page)

If I use the search for teams the link is going to be:

[localhost.com/page?search=NameOfTeam](http://localhost.com/page?search=NameOfTeam)

If I use the search for dates the link is going to be:

[localhost.com/page?on\_compiled=2009-06-30](http://localhost.com/page?on_compiled=2009-06-30)

as an example of todays dates…

Now, that’s all fine and dandy and they work, but since I use pagination  
and sort table views, that functionality defaults back to the root url.

For instance, I pull todays date and get:

[localhost.com/page?on\_compiled=2009-06-30](http://localhost.com/page?on_compiled=2009-06-30)

and then click ASC sort button next to a team…

[localhost.com/page](http://localhost.com/page)

and the special date criteria is gone.

I would like to implement this particular page so that all search forms  
and default behavior is similar…

[localhost.com/page?search=nil&compiled\_on=2009-06-30&sort=ASC](http://localhost.com/page?search=nil&compiled_on=2009-06-30&sort=ASC)

etc…

I know how to do this in PHP but not with rails. I’m just looking for  
some pointers…
