# AWS and array of Model

**URL:** <https://www.ruby-forum.com/t/aws-and-array-of-model/51756>\
**Category:** Rails\
**Created:** [January 6, 2006, 7:48pm UTC](https://www.ruby-forum.com/t/aws-and-array-of-model/51756 "2006-01-06T19:48:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![HSSSSber\_JSSSSnos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ccd318/32.png) [@HSSSSber\_JSSSSnos](https://www.ruby-forum.com/u/HSSSSber_JSSSSnos)\
**Post date:** [January 6, 2006, 7:48pm UTC](https://www.ruby-forum.com/t/aws-and-array-of-model/51756/1 "2006-01-06T19:48:43Z")

</div>

Hi!

I try to use a layered webservice and I want to get back an array of  
users;

In the API I use:  
api\_method :listUsers,:returns=\>[[User]]

in the service:  
def listUsers  
User.find(:all)  
end

Result in soap mode:

Don’t know how to cast TrueClass to Object

Result in XML-RPC mode:

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occured while evaluating nil.collect

It’s work on another machine. (Here is windows)  
I tried to create another ampty project with Only this model, and only  
one controller.

In controller used this code (the model is the default generated):  
class UserAdminAPI \< ActionWebService::API::Base  
api\_method :listUsers,:returns=\>[[User]]  
end

class UserAdminService \< ActionWebService::Base  
web\_service\_api UserAdminAPI

```
def listUsers
    User.find(:all)
end

```

end

class AdminController \< ApplicationController  
wsdl\_service\_name ‘Admin’  
web\_service\_dispatching\_mode :delegated  
web\_service\_scaffold :invoke  
web\_service(:user) { UserAdminService.new }  
end

What’s the problem? (If I change the return variable to :string and I in  
the implementation I use YAML.dump User.find(:all). It’s get back the  
value.

the flul log: [http://www.rafb.net/paste/results/PNmYct37.html](http://www.rafb.net/paste/results/PNmYct37.html)

Cow

---

<div class="post-metadata">

**Author:** ![HSSSSber\_JSSSSnos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ccd318/32.png) [@HSSSSber\_JSSSSnos](https://www.ruby-forum.com/u/HSSSSber_JSSSSnos)\
**Post date:** [January 7, 2006, 5:57pm UTC](https://www.ruby-forum.com/t/aws-and-array-of-model/51756/2 "2006-01-07T17:57:09Z")

</div>

Yeah, I have a very similar problem. I want my webservice to return say  
a Person object, but when I invoke the method through SOAP I get “Don’t  
know how to cast FalseClass to Object”, and through XML-RPC I get a  
whiney NULL error.

I have used the exact example from the Agile Rails book … have you  
managed to solve your problem yet?

Joerg

P.S. It all works fine if my methods return integers or strings.

HÃ¡ber JÃ¡nos wrote:

> Hi!
> 
> I try to use a layered webservice and I want to get back an array of  
> users;
> 
> In the API I use:  
> api\_method :listUsers,:returns=\>[[User]]
> 
> in the service:  
> def listUsers  
> User.find(:all)  
> end
> 
> Result in soap mode:
> 
> Don’t know how to cast TrueClass to Object
> 
> Result in XML-RPC mode:
> 
> You have a nil object when you didn’t expect it!  
> You might have expected an instance of Array.  
> The error occured while evaluating nil.collect
> 
> It’s work on another machine. (Here is windows)  
> I tried to create another ampty project with Only this model, and only  
> one controller.
> 
> In controller used this code (the model is the default generated):  
> class UserAdminAPI \< ActionWebService::API::Base  
> api\_method :listUsers,:returns=\>[[User]]  
> end
> 
> class UserAdminService \< ActionWebService::Base  
> web\_service\_api UserAdminAPI
> 
> ```
> def listUsers
> User.find(:all)
> end
> 
> ```
> 
> end
> 
> class AdminController \< ApplicationController  
> wsdl\_service\_name ‘Admin’  
> web\_service\_dispatching\_mode :delegated  
> web\_service\_scaffold :invoke  
> web\_service(:user) { UserAdminService.new }  
> end
> 
> What’s the problem? (If I change the return variable to :string and I in  
> the implementation I use YAML.dump User.find(:all). It’s get back the  
> value.
> 
> the flul log: [http://www.rafb.net/paste/results/PNmYct37.html](http://www.rafb.net/paste/results/PNmYct37.html)
> 
> Cow

---

<div class="post-metadata">

**Author:** ![HSSSSber\_JSSSSnos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ccd318/32.png) [@HSSSSber\_JSSSSnos](https://www.ruby-forum.com/u/HSSSSber_JSSSSnos)\
**Post date:** [January 7, 2006, 8:40pm UTC](https://www.ruby-forum.com/t/aws-and-array-of-model/51756/3 "2006-01-07T20:40:05Z")

</div>

Hi!

I think you are use postgresql or other database which have real boolean  
type (mysql boolean type is an alias to int(1)). And the Webservice  
can’t cast this type to primitive.

Cow

Joerg D. Ã­rta:

---

<div class="post-metadata">

**Author:** ![HSSSSber\_JSSSSnos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ccd318/32.png) [@HSSSSber\_JSSSSnos](https://www.ruby-forum.com/u/HSSSSber_JSSSSnos)\
**Post date:** [January 7, 2006, 9:40pm UTC](https://www.ruby-forum.com/t/aws-and-array-of-model/51756/4 "2006-01-07T21:40:23Z")

</div>

I am using MySql, and don’t have any booleans either … but I’ll see if  
it can have anything to do with my table columns. But at the moment  
(well, the past few days) it looks like a bug to me in Rails.

---

<div class="post-metadata">

**Author:** ![HSSSSber\_JSSSSnos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ccd318/32.png) [@HSSSSber\_JSSSSnos](https://www.ruby-forum.com/u/HSSSSber_JSSSSnos)\
**Post date:** [January 7, 2006, 10:49pm UTC](https://www.ruby-forum.com/t/aws-and-array-of-model/51756/5 "2006-01-07T22:49:49Z")

</div>

Hi!

I think the deleted is the problem. Rails automatically convert the  
“deleted” field to boolean. because WS can’t convert boolean to Object  
so you can get the TrueClass can’t convert error.  
[http://wiki.rubyonrails.com/rails/pages/HowtoUseBooleanColumns](http://wiki.rubyonrails.com/rails/pages/HowtoUseBooleanColumns)

So the Rails is buggy…

Cow

Joerg D. Ã­rta:

---

<div class="post-metadata">

**Author:** ![HSSSSber\_JSSSSnos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ccd318/32.png) [@HSSSSber\_JSSSSnos](https://www.ruby-forum.com/u/HSSSSber_JSSSSnos)\
**Post date:** [January 7, 2006, 10:04pm UTC](https://www.ruby-forum.com/t/aws-and-array-of-model/51756/6 "2006-01-07T22:04:25Z")

</div>

Right. If I return a User object from my AWS, everything is cool when I  
use XML-RPC (SOAP gives me an error: Cannot map User to SOAP/OM.).

However, if I return a Brand object from my AWS, I get the errors  
mentioned in the first email of this thread.

I can’t see a difference though in these tables that would cause this  
differing behaviour. I have added a tinyint(1) and a text field to User,  
and it still works with those fields.

Perhaps I am using field names that I shouldn’t?

CREATE TABLE `users` (  
`id` int(11) unsigned NOT NULL auto\_increment,  
`type` varchar(20) default NULL,  
`username` varchar(50) NOT NULL default ‘’,  
`name` varchar(50) NOT NULL default ‘’,  
`parent_id` int(11) default NULL,  
`email` varchar(100) NOT NULL default ‘’,  
`updated_on` datetime default NULL,  
`created_on` datetime default NULL,  
PRIMARY KEY (`id`)  
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `brands` (  
`id` int(11) unsigned NOT NULL auto\_increment,  
`name` varchar(100) NOT NULL default ‘’,  
`abbreviation` varchar(11) NOT NULL default ‘’,  
`description` text NOT NULL,  
`image` varchar(100) default NULL,  
`image_timestamp` datetime default NULL,  
`position` int(11) default NULL,  
`deleted` tinyint(1) NOT NULL default ‘0’,  
PRIMARY KEY (`id`)  
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

---

<div class="post-metadata">

**Author:** ![HSSSSber\_JSSSSnos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ccd318/32.png) [@HSSSSber\_JSSSSnos](https://www.ruby-forum.com/u/HSSSSber_JSSSSnos)\
**Post date:** [January 8, 2006, 5:01pm UTC](https://www.ruby-forum.com/t/aws-and-array-of-model/51756/7 "2006-01-08T17:01:28Z")

</div>

Yeah that was it. Thanks.
