Time dropdown for best_in_place

I'm trying to add the proper syntax for the best_in_place gem with my code here:

<%= Time.at(task.hour).strftime("%I:%M %p") %>

I've tried something like

<%= best_in_place Time, :at(task.hour), :strftime("%I:%M %p") %> 

but that doesn't seem to work. Any pointers on this one?


You can use the display_with attribute of BIP, and in your config/environments/xxx.rb files add a custom time format method. Also instead of the Time model you should use the actual object, which looks to be task in this case and the time attribute is hour?

in view :

<%= best_in_place task, :hour, :display_with => lambda { |t| t.to_s(:non_military_time) } %>

in config/environments/development.rb, config/environments/production.rb, config/environments/test.rb (or I'm sure there's a single place you could declare it, but this is how I did it in past):

Time::DATE_FORMATS[:non_military_time] = "%I:%M %p"

You can also use %l in place of %I in the definition if you don't want the leading zero in the time. Hope this helps someone even though this is an old question!

Need Your Help

Proper usage of array as field member in VB 2005

vb.net arrays visual-studio-2005

I normally use C# and I'm attempting to convert a qbasic programmer to the joys of object oriented programming by easing him into VB 2005.

From a technical perspective, how does Selenium click an element on a web page?

selenium selenium-webdriver web-component polyfills remotewebdriver

Context is provided in case anyone knows of an alternative way to solve the larger issue.