Ruby on Rails 3: How to create a 12 hour (with AM/PM) time select element?
From what I can tell by looking in the Rails source code, it looks like all the methods are there. I just can't figure out how to call time_select
with the right options to enable 12 hour and add a AM/PM select element. What options do I need pass in order to create this?
Here are开发者_如何转开发 a few things that I've tried:
<%= form_for(@post) do |f| %>
<div class="field">
<%= f.label :created_at %><br />
<%= f.time_select :created_at, :ampm => true #didnt do anything %>
<%= time_select('post', 'created_at', { :ampm => true }) #also didnt do anything %>
</div>
<% end %>
time_select("post", "written_on", {:ampm => true})
Update You need to update your Rails version. The ampm selector was added in this commit
commit a869382a9fa241f72a7a73d4a9738531c4c37ba5 Author: Aditya Sanghi Date: Fri Apr 29 01:49:45 2011 +0530
Allow AM/PM in datetime selectors
which is not in 3.0.x. Sorry.
精彩评论