Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 %>
like image 543
Andrew Avatar asked Jul 16 '11 20:07

Andrew


1 Answers

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.

like image 107
Ray Baxter Avatar answered Oct 23 '22 09:10

Ray Baxter