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

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -