For example, let''s say I have a User model with 2 attributes: 1. pw_hash 2. pw_salt I don''t want these to show up in the to_xml method. How do I keep to_xml from using these attributes? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hey Ben On Feb 15, 2007, at 9:01 AM, Ben Johnson wrote:> For example, let''s say I have a User model with 2 attributes: > > 1. pw_hash > 2. pw_salt > > I don''t want these to show up in the to_xml method. How do I keep > to_xml > from using these attributes?You can specify what you don''t want using except: user.to_xml :except => [: pw_hash, : pw_salt] Andy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2/15/07, Ben Johnson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > For example, let''s say I have a User model with 2 attributes: > > 1. pw_hash > 2. pw_salt > > I don''t want these to show up in the to_xml method. How do I keep to_xml > from using these attributes?Look at the :except option: http://rails.rubyonrails.org/classes/ActiveRecord/XmlSerialization.html#M000910 If you want to make this default you can just override it in your model: to_xml(options = {}) super(options.update(:except => [:pw_hash, :pw_salt])) end -- Rick Olson http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
http://www.railsmanual.org/module/ActiveRecord%3A%3AXmlSerialization/to_xml @user.to_xml(:except => :pw_hash, :pw_salt) On 2/15/07, Ben Johnson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > For example, let''s say I have a User model with 2 attributes: > > 1. pw_hash > 2. pw_salt > > I don''t want these to show up in the to_xml method. How do I keep to_xml > from using these attributes? > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---