ruby on rails - ActiveRecord : Hide column while returning object -
is there out-of-the-box way hide/remove column (say, user.password) while returning activerecord object ? thanks.
using built-in serialization, can override as_json
method on model pass in additional default options:
class user < activerecord::base # ... def as_json(options = {}) super(options.merge({ except: [:password, :oauth_token] })) end end
there better serialization tools out there - if looking more fine-grained control recommend checking out active_model_serializers
or rabl
.
Comments
Post a Comment