hungrylist-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-18  15:20 UTC
making an attribute private in ActiveRecord
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---