Skip to content

tjobrien/Date_and_Time-samples

Repository files navigation

A small project that uses JQuery datepicker, formtastic, event_calendar, validates_timeliness and chronic.

The issue I was trying to solve was how to integrate all these and allow users to choose a date and time easily.  IMHO that is
choose a date from a calendar, then choose the time from select boxes.  Because this is an event, a User nust also choose duration.


1.  JQuery - look at application.js....I changed the default Date format of the datepicker to YY-MM-DD.  Chronic can parse DD-MM-YY to a correct
date format for ActiveRecord, but I needed a way to validate user input.  My app uses YY-MM-DD format, so not an inconvenient trade off.

2.  Event_calendar
The event_calendar needs a start_at and end_at to create the calendar.
I take the start_at_date, start_at_hour, start_at_minute and am_pm attributes and parse a start_date from those values in the 
Event befor_save callback.  In the same method, I create the end_at by using rails some_integer.minutes.since self.start_at
I use the all_day flag.  As the has_event_calendar method has a before_save call in it, the date parsing I needed to create these dates was
failing.  I put the has_event_calendar below the before_save :date_parser call and then event_calendar can do its thing as it has a start_date.

3.  The rest is pretty straight forward...there are few extra date and time fields in the views/events/_form.html.erb so you can see how those look too.
4. No testing..I know.

About

combines JQueryUI datepicker and event_calendar in a Rails 3.0 project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published