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

Popular posts from this blog

ruby - Nesting modules inside of a Rails eninge gem -

Eclipse formatter for java ending braces -

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -