views:

37

answers:

2

Hi everyone,

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!

A: 

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.

corroded
+1  A: 

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

vrsmn