ActiveRecord : Hide column while returning object
问题 Is there an out-of-the-box way to always hide/remove a column (say, User.password) while returning an ActiveRecord object ? Thanks. 回答1: Using the built-in serialization, you can override the as_json method on your model to pass in additional default options: class User < ActiveRecord::Base # ... def as_json(options = {}) super(options.merge({ except: [:password, :oauth_token] })) end end There are probably better serialization tools out there - if you are looking for more fine-grained