# ActiveResource find method and restful controllers

**URL:** <https://www.ruby-forum.com/t/activeresource-find-method-and-restful-controllers/112706>\
**Category:** Rails\
**Created:** [August 22, 2007, 12:47pm UTC](https://www.ruby-forum.com/t/activeresource-find-method-and-restful-controllers/112706 "2007-08-22T12:47:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tobycatlin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@tobycatlin](https://www.ruby-forum.com/u/tobycatlin)\
**Post date:** [August 22, 2007, 12:47pm UTC](https://www.ruby-forum.com/t/activeresource-find-method-and-restful-controllers/112706/1 "2007-08-22T12:47:39Z")

</div>

Hi,

What’s the best way to add support for the activeresource find method  
in the controllers in my rails app?

As I understand it when you invoke something like:  
Person.find(:all, :params =\> {:name = ‘toby’})

this generates a request of:  
GET /people.xml?name=toby

Does this mean that in my index method in PeopleController in my rails  
app I have params[name] set to toby?

What is the best was of returning useful data from this find from  
within my controller i.e., how do I construct a find in the  
controller?

Thanks,  
Toby

---

<div class="post-metadata">

**Author:** ![tobycatlin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5e9695/32.png) [@tobycatlin](https://www.ruby-forum.com/u/tobycatlin)\
**Post date:** [August 22, 2007, 9:06pm UTC](https://www.ruby-forum.com/t/activeresource-find-method-and-restful-controllers/112706/2 "2007-08-22T21:06:09Z")

</div>

Ok so after a bit of playing I can answer half of my question but I  
have also come up with what seems to be a problem with activeresource.

By invoking Person.find(:all, :params =\> {:name =\> ‘toby’}) a request  
of GET /people.xml?name=toby is created and then in the controller  
this appears in the params hash as params[:name]

Currently I am using the following code in my controller but I don’t  
think it is a very way to do what I want to do:

def index  
if params[:name]  
@people = Person.find(:first, :conditions =\> [“name = ?”,  
params[:name]])  
raise(ActiveRecord::RecordNotFound, “Couldn’t find person with  
name #{params[:name]}”) unless @people  
else  
@data\_dates = People.find(:all)  
end

respond\_to do |format|  
format.xml { render :xml =\> @people }  
end  
end

Unfortunately at the activeresource end this generates the error

NoMethodError: undefined method `collect!’ for #Hash:0xb12ab325

I found this ticket but after applying the patch I still have the same  
problem: [http://dev.rubyonrails.org/ticket/8798](http://dev.rubyonrails.org/ticket/8798)

If anyone has any suggestion at all I would be grateful as I am pretty  
lost now…

Thanks

Toby
