half way from re-building an object .... just a little bit of brain..

I found that it's easy w Rails 2.0 to deserialize !

data = XmlSimple.xml_in(result)
v = Hash.from_xml(result).values.first

=> {"membership_at"=>"2007-03-28T21:25:31Z",
"display_name"=>"chane850", "first_name"=>nil, "last_name"=>nil}

so now how can I build an ActiveRecord-like object (don't want to
create a table)

Membership class with these attributes ?

@membership = Membership.new.build( v ) ? doesn' t work

any clue ?

thanks

Create this class, called tableless.rb in your app/models folder

Table-less model used for any object that needs validation or for

any web form that does not need a database.

Idea and concept from Rick Olson

class Tableless < ActiveRecord::Base
def self.columns()
@columns ||= [];
end

def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::
Column.new(name.to_s, default,
sql_type.to_s, null)
end

override the save method to prevent exceptions.

def save(validate = true)
validate ? valid? : true
end

end

Now just create a new class called Membership (app/models/membership.rb)

class Membership < Tableless
column :display_name, :string
column :first_name, :string
column :last_name, :string

column :membership_at, :datetime

validates_presence_of :display_name, :first_name, :last_name, membership_at

end

And then get ready to rock.

m = Membership.new(hash_from_xml)

if m.valid?

do stuff

else

do other failure stuff

end

Throw your other membership business rules in the membership.rb class too.

I use this technique for contact forms, etc that don’t need backends.