Hiding Model Attribute

I have a model object for which I would like to effectively hide one
attribute (a password hash) so that it is never returned by a find_*
call. I have tried several unsuccessful means. Is there a simple way
to do this that I am overlooking?

Thanks,
Doug

I think that you could add something like this to your model class:

def self.password_hash
return ‘’
end

the field would be returned by the sql query anyway, but it woun’t
be “readable” by your code… just an “on the fly” idea… hope it
helps

Doug Selph
escribió:

I have a model object for which I would like to effectively hide one

Doug Selph wrote:

I have a model object for which I would like to effectively
hide one attribute (a password hash) so that it is never
returned by a find_* call. I have tried several unsuccessful
means. Is there a simple way to do this that I am
overlooking?

Since the attribute method doesn’t actually exist, you can only
preempt calls to #method_missing by creating a real method,
like another person mentioned. However, I would create a
crutch for the rest of the class so you don’t have to muck with
@attributes just to get to the password:

def method_missing(method_id, *args, &block)
method_id == :password ? “No soup for you” : super
end

def password
read_attribute(:password)
end

def password=(pass)
write_attribute(:password, pass)
end

private :password, :password=

-Drew

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs