1
我试图用我的代码在这里添加正确的语法为best_in_place宝石:时间为下拉best_in_place
<%= Time.at(task.hour).strftime("%I:%M %p") %>
我已经试过类似
<%= best_in_place Time, :at(task.hour), :strftime("%I:%M %p") %>
但不似乎工作。任何指针在这一个?
我试图用我的代码在这里添加正确的语法为best_in_place宝石:时间为下拉best_in_place
<%= Time.at(task.hour).strftime("%I:%M %p") %>
我已经试过类似
<%= best_in_place Time, :at(task.hour), :strftime("%I:%M %p") %>
但不似乎工作。任何指针在这一个?
你可以使用BIP的display_with属性,并在你的config/environments/xxx.rb文件中添加一个自定义的时间格式方法。另外,而不是时间模型,你应该使用实际的对象,这看起来是任务在这种情况下,时间属性是小时?
鉴于:
<%= best_in_place task, :hour, :display_with => lambda { |t| t.to_s(:non_military_time) } %>
在配置/环境/ development.rb,配置/环境/ production.rb,配置/环境/ test.rb
(或我敢肯定有你可以在一个地方声明它,但是这是我做到了在过去):
Time::DATE_FORMATS[:non_military_time] = "%I:%M %p"
可以代替%I
的定义也使用%l
,如果你不希望在时间的前导零做。希望这可以帮助某人,即使这是一个老问题!