Just started using Rails and was stumped by the following problem. I want to create an application that tracks a user’s runs/rides/activities where an activity is defined by a start date (datetime), duration (integer, number of seconds) and distance (integer, number of m traveled).
Creating a form that lets the user input these values is simple enough using the form_with helper. But it’s far from a good user experience. What I would like to achieve is to have three separate text fields for inputting the duration (hours/minutes/seconds). There needs to be a translation from the model’s duration in seconds to the views three fields and vice versa when submitting the form. But where exactly do I put this translation? What is the Rails way of doing non-standard model form input?
Do I just add three form fields not associated with the model in the form_with helper in my view and handle the translation in the controller? Is there a better way? Would be grateful if anyone had any examples of this kind of form handling.