I have a view that takes a Ruby Date, performs some formatting on it to output just the time in the format [5:30 PM]. Then by default it adds 30 minutes to that so the result is similar to the following output:
5:30 PM - 6:00 PM
and the code in the haml file looks like:
=format_time( @time ) + " - " + format_time( Time.parse( @time ).advance( :minutes => 30 ) )
where format_time is a method I created.
But then the user can change the 'duration' by changing a combobox selection. Let's say the user chooses '60' in the combobox, I need to the add 60 minutes to the start time and update the output to read:
5:30 PM - 6:30 PM
The problem is that when the page first loads, the formatting happens in my Ruby method format_time. But after the combobox selection I think the formatting has to be done in Javascript triggered by the 'onchange' event on the combobox. But that means I have to maintain two different methods to do the same formatting.
Is there a better solution to this?