I’m working on my first Rails Application. I am a little stuck with the time. I’m working on a recipe application. I need to add two fields.
- Preparation Time
- Cook Time
Out of the two, i would like to add the two fields to come up with the Total Time needed to prepare the meal.
I approached it the wrong way which doesn’t have logic :(. Basically i have two fields and i used f.select to select predefined times. But the problem i have with that approach is that when adding the two, it ignores the Gregorian format e.g 40 minutes + 50 mins will become 90 Min instead of 1hour 30.
I would appreciate any help from the community.
A quick example:
If you wanted 90 minutes instead:
Update:
Put this in the helper file associated with whatever view you are using this in (i.e.
app/helpers/recipes_helper.rb)Then you’d just call it in your view (i.e.
app/views/recipes/show.html.hamllike:If you are storing the times in the database as integers (which you SHOULD be doing), then you can do this:
where
@recipe.prep_timeis an integer with a value of 40 and@recipe.cook_timeis an integer with a value of 50and your database schema would look something like: