Hi there
I'm wondering which is the right way to make an attribute of an Activerecord class private so not accessible from the outside of the class itself. Let's say that my SQL schema for the class is something like this, just to make it simple
Elements table
id int title varchar numvalue int
and my activeRecord class will be this way
class Element < ActiveRecord::Base def outvalue numvalue*100 end end
I want to forbid the access to the method element.numvalue because I need to have the value accessed from the external classes only with the outvalue method. Please note that overwriting or aliasing the value method with outvalue is not a suitable solution for me.
I've tried this http://rails.techno-weenie.net/question/2006/3/7/making_ar_attriibutes_private but simply doesn't work, what happens in this case is that the new defined methods are there and raise an exception when called since they are private methods, but the exception is raised in "method_missing" so the ActiveRecord class will provide his standard accessor method through method_missing so in the end nothing change and the methods are still public.
Thanks
Paolo