How to convert user input hours, minutes, seconds - both ways

In my model I have an attribute “duration” (seconds as an integer) But
the views new/edit have input for: hours, minutes, seconds.

Should I have in model (attr_accessor :hours, :minutes, :seconds) then
how do I convert these virtual attributes into my “duration”
attribute, Coming from Java I’d have setter/getter on “duration”!

Mohammad A. wrote:

In my model I have an attribute “duration” (seconds as an integer) But
the views new/edit have input for: hours, minutes, seconds.

Should I have in model (attr_accessor :hours, :minutes, :seconds) then
how do I convert these virtual attributes into my “duration”
attribute, Coming from Java I’d have setter/getter on “duration”!

You can certainly do that in Ruby too. Also check out composed_of. The
Runt gem might be helpful for dealing with time expressions.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]