Forum: Ruby on Rails Return type of Finder? How to append?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
442f1c05ac02e1934cde594a185807a9?d=identicon&s=25 Tony Puthenveettil (tonyputhenveettil)
on 2009-01-22 14:54
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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-01-22 15:35
(Received via mailing list)
On 22 Jan 2009, at 13:54, Tony Puthenveettil 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
442f1c05ac02e1934cde594a185807a9?d=identicon&s=25 Tony Puthenveettil (tonyputhenveettil)
on 2009-01-23 05:48
Frederick Cheung wrote:
> On 22 Jan 2009, at 13:54, Tony Puthenveettil 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?
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-01-23 10:50
(Received via mailing list)
Have a look at the documentation for Array, method '+' may be of
interest.
See http://www.ruby-doc.org/core/classes/Array.html

2009/1/23 Tony Puthenveettil <rails-mailing-list@andreas-s.net>
442f1c05ac02e1934cde594a185807a9?d=identicon&s=25 Tony Puthenveettil (tonyputhenveettil)
on 2009-01-23 11:02
Colin Law wrote:
> Have a look at the documentation for Array, method '+' may be of
> interest.
> See http://www.ruby-doc.org/core/classes/Array.html
>
> 2009/1/23 Tony Puthenveettil <rails-mailing-list@andreas-s.net>

Thanks Colin...
This topic is locked and can not be replied to.