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"!
Marnen Laibow-Koser
2009-Sep-15 03:59 UTC
Re: How to convert user input hours, minutes, seconds - both
Mohammad Abed 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 marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.