Reputation: 56789
I have a simple text_field in my form where a user enters a time in minutes, i.e. 60.
How can I multiply that number by 60 before saving the form, such that the database stores the number in seconds?
Then, how do I reverse that and show the field in minutes on another view?
Thank you!
Upvotes: 0
Views: 111
Reputation: 625
you could create a method in you model called "time_in_seconds" that multiply your time and stores it in the correct place.
It should be more DRY since you'll have access to your model in every controller/view and will have the same method for all
Upvotes: 1
Reputation: 21604
In your controller, multiply the variable by 60 before calling the save function of your model
To show that, in your view or in your controller's show function just divide the number by 60.
Upvotes: 0