However, by default it outputs every field in the model, which exposes some data (encrypted-password and password-salt) that I’d rather keep to myself :
If you find yourself doing this in a lot of different places, it may be easier to filter these options at the model level, by over-riding the ‘to_json’ and ‘to_xml’ methods :
12345678910111213141516171819
classUser<ActiveRecord::Base...# Exclude password info from xml output.defto_xml(options={})options[:except]||=[:encrypted_password,:password_salt]super(options)end# Exclude password info from json output.defto_json(options={})options[:except]||=[:encrypted_password,:password_salt]super(options)end...end