Michael King
2005-Jul-06 15:31 UTC
easy way to store attributes as integer but edit as hex?
I have 2 attributes that I am storing as integers (not by my choice) that I need to display/edit in hex. What is the easiest way to do this? Currently I have my edit fields set up as text_field_tag and I do a str.hex conversion in the controller, but now I am having problems in the edit screen with the field not being populated and in the list screen showing the integer. I can solve the edit screen issue by providing a default value. The list screen I''m not sure how to resolve and I am starting to think that I am doing this the hard way. Am I? - Michael
John Higgins
2005-Jul-06 15:41 UTC
Re: easy way to store attributes as integer but edit as hex?
Easiest way that I know of would be to go with a new field that just passes/retreives values to the original field class MyTable < ActiveRecord::Base def fieldA_hex #fieldA converted to hex end def fieldA_hex #convert back to hex and call fieldAend end Then use fieldA_hex when you need to set or get the hex value -- John W Higgins wishdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Michael King
2005-Jul-06 16:17 UTC
Re: easy way to store attributes as integer but edit as hex?
This is exactly why I like this list, I knew I was doing things the hard way. On 7/6/05, John Higgins <wishdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Easiest way that I know of would be to go with a new field that just > passes/retreives values to the original field > > class MyTable < ActiveRecord::Base > def fieldA_hex > #fieldA converted to hex > end > > def fieldA_hex> #convert back to hex and call fieldA> end > end > > Then use fieldA_hex when you need to set or get the hex value > > > -- > John W Higgins > wishdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >