Evanto
Evanto

Reputation: 350

Rails Hours:Minutes Dropdowns

I'm new to Rails and I want to create a simple time calculator: User is presented with 2 dropdown menus that capture user inputs “hour” and “minutes”, so I can get time like 7:15. Then after some math on this time the user is given several “hour:minute” time options. What is the best way to build this logic and what helper to use? Should I create models for hours and minutes?

Upvotes: 2

Views: 1028

Answers (2)

Vishwas Nahar
Vishwas Nahar

Reputation: 418

You can build up the hour and minutes drop down.

<%= f.select :hours, '1'..'24' %>

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

or you can use gem

Upvotes: 2

Sajin
Sajin

Reputation: 1638

You can use time_select to get hours and minutes from user.

Upvotes: 2

Related Questions