# Return type of Finder? How to append?

**URL:** <https://www.ruby-forum.com/t/return-type-of-finder-how-to-append/158367>\
**Category:** Rails\
**Created:** [January 22, 2009, 2:54pm UTC](https://www.ruby-forum.com/t/return-type-of-finder-how-to-append/158367 "2009-01-22T14:54:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [January 22, 2009, 2:54pm UTC](https://www.ruby-forum.com/t/return-type-of-finder-how-to-append/158367/1 "2009-01-22T14:54:47Z")

</div>

Hi all,

Please help me solve the issue given below.

Scenario:  
I’m fetching few rows from one table to a variable. Then I want to  
append that variable with another row of the same table, based on a  
condition.

For that, I used push function with that variable, thinking the return  
type of Finder is array or hash. But, it gives me Undefined Method  
error.

Code Snippet:  
#Controller  
@selected = Project.find(:all, :conditions =\> “id \<= 4”)  
@selected.push Project.find(:all, :conditions =\>[‘id \>?’, params[:id]])

Please help me tackle this issue.

This is for the functionality of drag & drop with two list. It would be  
very helpful, if you can give me a simple and complete example of the  
same as well.

A prompt reply would be appreciated.

Thanks,  
Tony Puthenveetil

---

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [January 22, 2009, 3:35pm UTC](https://www.ruby-forum.com/t/return-type-of-finder-how-to-append/158367/2 "2009-01-22T15:35:40Z")

</div>

On 22 Jan 2009, at 13:54, Tony P. wrote:

> For that, I used push function with that variable, thinking the return  
> type of Finder is array or hash. But, it gives me Undefined Method  
> error.
> 
> Code Snippet:  
> #Controller  
> @selected = Project.find(:all, :conditions =\> “id \<= 4”)  
> @selected.push Project.find(:all, :conditions =\>[‘id \>?’,  
> params[:id]])

push is almost certainly not what you want as it adds the argument at  
the end of the array (even if the argument is an array)  
for example:  
[1,2].push [3,4] #=\> [1, 2, [3, 4]]  
whereas i expect you want to get [1,2,3,4]

Fred

---

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [January 23, 2009, 5:48am UTC](https://www.ruby-forum.com/t/return-type-of-finder-how-to-append/158367/3 "2009-01-23T05:48:23Z")

</div>

Frederick C. wrote:

> On 22 Jan 2009, at 13:54, Tony P. wrote:
> 
> > For that, I used push function with that variable, thinking the return  
> > type of Finder is array or hash. But, it gives me Undefined Method  
> > error.
> > 
> > Code Snippet:  
> > #Controller  
> > @selected = Project.find(:all, :conditions =\> “id \<= 4”)  
> > @selected.push Project.find(:all, :conditions =\>[‘id \>?’,  
> > params[:id]])
> 
> push is almost certainly not what you want as it adds the argument at  
> the end of the array (even if the argument is an array)  
> for example:  
> [1,2].push [3,4] #=\> [1, 2, [3, 4]]  
> whereas i expect you want to get [1,2,3,4]
> 
> Fred

Dear Fred, You are there… right. Thanks for the information.

Could anybody please help me append the data, explained above?

---

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [January 23, 2009, 11:02am UTC](https://www.ruby-forum.com/t/return-type-of-finder-how-to-append/158367/4 "2009-01-23T11:02:32Z")

</div>

Colin L. wrote:

> Have a look at the documentation for Array, method ‘+’ may be of  
> interest.  
> See [class Array - RDoc Documentation](http://www.ruby-doc.org/core/classes/Array.html)
> 
> 2009/1/23 Tony P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Thanks Colin…

---

<div class="post-metadata">

**Author:** ![tnyplz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f17d59/32.png) [@tnyplz](https://www.ruby-forum.com/u/tnyplz)\
**Post date:** [January 23, 2009, 10:50am UTC](https://www.ruby-forum.com/t/return-type-of-finder-how-to-append/158367/5 "2009-01-23T10:50:28Z")

</div>

Have a look at the documentation for Array, method ‘+’ may be of  
interest.  
See [class Array - RDoc Documentation](http://www.ruby-doc.org/core/classes/Array.html)

2009/1/23 Tony P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
