#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

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

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

Source available from github

The Git repository resides at http://github.com/rails

Check out the current development trunk (Edge Rails) with:

git clone git://github.com/rails/rails.git

Creating or reviewing a patch

See the contributor guide.

Creating a feature request

Please don't. If you want a new feature in Rails, you'll have to pull up your sleeves and get busy yourself. Or convince someone else to do it. See the contributor guide on how to get going. But posting them here is just going to lead to ticket root.

Creating a bug report

When creating a bug report, be sure to include as much relevant information as possible. Post the code sample that causes the problem. Preferably, alter the unit tests and show through either changed or added tests how the expected behavior is not occuring.

Security vulnerabilities should be reported via an email to security@rubyonrails.org, do not use trac for reporting security vulnerabilities. All content in trac is publicly available as soon as it is posted.

Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kinda bug, you're creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to sign on to with a "I'm having this problem too".

Shared Ticket Bins

People watching this ticket