I have a class called Duration that represents a unit of time. It has lots of time-related methods and an attribute that represents the duration in seconds. I want to store it in my db. I had a column type of NUMERIC, so if i save it, rails trys to coerce it to a float automagically and fails. I need to display it and store it as a number but treat it in the middle layer as a Duration so I can use all it''s wonderful functionality. What''s the right way to do this? thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060318/c41e206b/attachment.html
Francois Beausoleil
2006-Mar-19 02:00 UTC
[Rails] rails-y way to handle quasi-numeric type
Hello Larry, 2006/3/18, Larry White <ljw1001@gmail.com>:> I need to display it and store it as a number but treat it in the middle > layer as a Duration so I can use all it''s wonderful functionality. What''s > the right way to do this?You want to use composed_of class UserOfDuration < ActiveRecord::Base composed_of :project_length, :class_name => ''Duration'', :mappings => %w(duration_in_seconds duration) end http://api.rubyonrails.com/classes/ActiveRecord/Aggregations/ClassMethods.html#M000692 Hope that helps ! -- Fran?ois Beausoleil http://blog.teksol.info/