2013-05-05 38 views
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") %> 

但不似乎工作。任何指針在這一個?

回答

0

你可以使用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,如果你不希望在時間的前導零做。希望這可以幫助某人,即使這是一個老問題!