user4227507
user4227507

Reputation:

Ruby on Rails Hours and Minutes in Drop Down Menu

In my Ruby on Rails application I am building a cinema application and for the length of each movie I want to display the hours and minutes in a drop down menu on the _form.html.erb. At the minute I am using two text fields (one for hours and one for minutes) so that a user can type in the hours and minutes, but I want to have these as drop down menus where, if the user is creating a new record, they can select an hour and minute, and, if the user is editing a record, the record's current hour and minute is shown. Can anyone help me?

_form.html.erb

<br>
Running Time:<br>
<%= f.text_field :hours, :size => 5 %> hours <%= f.text_field :minutes, :size => 5 %> minutes 
<br>

Upvotes: 1

Views: 1073

Answers (1)

Mark Swardstrom
Mark Swardstrom

Reputation: 18130

You can build up the hour and minutes drop down without using the time helpers.

<%= f.select :hours, '1'..'4' %>
<%= f.select :minutes, '01'..'59' %>

BTW - you may want to get these into integers to help validate input.

Upvotes: 1

Related Questions