def calendar_field(object_name, method, options = {})
object = instance_variable_get("@#{object_name}")
field_value = object.send(method) ? object.send(method).strftime("%m/%d/%Y") : ''
output = text_field object_name , method , :value => field_value
output += calendar_helper(object_name + "_" + method)
output
end
def calendar_helper(field_id)
'<script type="text/javascript">
Calendar.setup({
inputField : "'+ field_id + '", // id of the input field
ifFormat : "%m/%d/%Y", // format of the input field
showsTime : false,
timeFormat : "24",
singleClick : true
});
</script>'
end
and call it in your views like so
<%= calendar_field 'object', 'method' %>
Sure, you can combine both functions into one and add a date format as a param but so far this serves my quick and dirty needs.