从我通过查看 Rails 源代码可以看出,看起来所有的方法都在那里。我就是不知道怎么打time_select
使用正确的选项来启用 12 小时并添加 AM/PM 选择元素。为了创建它,我需要传递哪些选项?
以下是我尝试过的一些事情:
<%= 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})
更新
您需要更新 Rails 版本。在 this commit 中添加了 ampm 选择器
commit a869382a9fa241f72a7a73d4a9738531c4c37ba5 Author: Aditya Sanghi Date: Fri Apr 29 01:49:45 2011 +0530
Allow AM/PM in datetime selectors
这不在 3.0.x 中。对不起。
关于ruby-on-rails - Ruby on Rails 3 : How to create a 12 hour (with AM/PM) time select element?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6720015/