This project is archived and is in readonly mode.

#596 ✓stale
Baptiste Grenier

ActiveResource should handle multivalued attributes

Reported by Baptiste Grenier | July 10th, 2008 @ 06:04 PM | in 2.x

I am using ActiveResource to access a RESTfull WebService exposing LDAP[1] resources through the usage of ActiveLdap[2].

LDAP attributes[3] could be multivalued and some of them are often (objectClass or email as an example).

The ActiveLdap object represents this values as an array:

--------8

>> u.find('Baptiste Grenier')

>> u.mail

=> ["plop@plop.org", "toglut@toglut.org"]

--------8

I have contacted[4] the helpful ActiveLdap team in order to change the xml outputed by the to_xml method, and here is an extract of what the to_xml now produces:

--------8

cn=Baptiste Grenier,ou=people,dc=plop,dc=org

plop@plop.org

toglut@toglut.org

hgPerson

inetOrgPerson

--------8

But this does not make things works better with ActiveResource, as when I try to create a ActiveResource object from this resource, I get this error:

--------8

>> u = User.find('50')

ArgumentError: expected an attributes Hash, got "plop@plop.org"

from /usr/lib/ruby/gems/1.8/gems/activeresource-2.1.0/lib/active_resource/base.rb:883:in `load'

from /usr/lib/ruby/gems/1.8/gems/activeresource-2.1.0/lib/active_resource/base.rb:639:in `initialize'

from /usr/lib/ruby/gems/1.8/gems/activeresource-2.1.0/lib/active_resource/base.rb:890:in `new'

from /usr/lib/ruby/gems/1.8/gems/activeresource-2.1.0/lib/active_resource/base.rb:890:in `load'

from /usr/lib/ruby/gems/1.8/gems/activeresource-2.1.0/lib/active_resource/base.rb:890:in `map'

from /usr/lib/ruby/gems/1.8/gems/activeresource-2.1.0/lib/active_resource/base.rb:890:in `load'

from /usr/lib/ruby/gems/1.8/gems/activeresource-2.1.0/lib/active_resource/base.rb:885:in `each'

from /usr/lib/ruby/gems/1.8/gems/activeresource-2.1.0/lib/active_resource/base.rb:885:in `load'

from /usr/lib/ruby/gems/1.8/gems/activeresource-2.1.0/lib/active_resource/base.rb:639:in `initialize'

from /usr/lib/ruby/gems/1.8/gems/activeresource-2.1.0/lib/active_resource/base.rb:587:in `new'

from /usr/lib/ruby/gems/1.8/gems/activeresource-2.1.0/lib/active_resource/base.rb:587:in `instantiate_record'

from /usr/lib/ruby/gems/1.8/gems/activeresource-2.1.0/lib/active_resource/base.rb:579:in `find_single'

from /usr/lib/ruby/gems/1.8/gems/activeresource-2.1.0/lib/active_resource/base.rb:507:in `find'

from (irb):13

--------8

Perhaps if ActiveResource could be aware of a multivalued type (used in the to_xml like the array type) and then create an attribute as an array, it could be possible to handle such a situation.

Thanks for any help,

Baptiste

Ref:

[1]- http://tools.ietf.org/html/rfc2251

[2]- http://code.google.com/p/ruby-ac...

[3]- http://tools.ietf.org/html/rfc22....2.1

[4]- http://code.google.com/p/ruby-ac...

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages