# Query Problem, limiting list results

**URL:** <https://www.ruby-forum.com/t/query-problem-limiting-list-results/113635>\
**Category:** Rails\
**Created:** [September 3, 2007, 7:02am UTC](https://www.ruby-forum.com/t/query-problem-limiting-list-results/113635 "2007-09-03T07:02:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![myowntribe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a88e4f/32.png) [@myowntribe](https://www.ruby-forum.com/u/myowntribe)\
**Post date:** [September 3, 2007, 7:02am UTC](https://www.ruby-forum.com/t/query-problem-limiting-list-results/113635/1 "2007-09-03T07:02:08Z")

</div>

Hi all,

Could anyone please help me with this query?

I need to list user names and pictures of corresponding users and that  
too by limiting the list to just 5 users.

this is the error that occurs in the controller:

ArgumentError in User profilesController#mini\_friendlist

wrong number of arguments (2 for 1)

RAILS\_ROOT: ./script/…/config/…  
Application Trace | Framework Trace | Full Trace

#{RAILS\_ROOT}/app/controllers/user\_profiles\_controller.rb:24:in `find' #{RAILS_ROOT}/app/controllers/user_profiles_controller.rb:24:in`mini\_friendlist’

Also “friendship” variable is in the view(mini\_friendlist.rhtml):

\<% for friendship in @friends %\>  
\<img src="\<%=image\_path url\_for( :controller =\> “user\_pics”, :action =\>  
“show\_thumb”,  
:id =\> friendship.user\_pic ) %\>" /\>

\<%= friendship.name %\>  
\<% end %\>

Heres the controller code:

```
 def mini_friendlist

```

@friend = User.find(session[:user\_id])  
@user = User.find(params[:id])  
@friends = @user.friends.find(:all,  
:limit =\> “5”)

end

When I write this query I get a wrong argument error.

Please guide me with this task… any help is appreciated.

Cheers

Cass

---

<div class="post-metadata">

**Author:** ![myowntribe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a88e4f/32.png) [@myowntribe](https://www.ruby-forum.com/u/myowntribe)\
**Post date:** [September 3, 2007, 9:09am UTC](https://www.ruby-forum.com/t/query-problem-limiting-list-results/113635/2 "2007-09-03T09:09:43Z")

</div>

in controller write like this

```
@friend = User.find(params[:id])
@friends = User.find(:all, :conditions => ["LIKE ?", <what u want

```

to find\>])

---

<div class="post-metadata">

**Author:** ![myowntribe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a88e4f/32.png) [@myowntribe](https://www.ruby-forum.com/u/myowntribe)\
**Post date:** [September 3, 2007, 9:33am UTC](https://www.ruby-forum.com/t/query-problem-limiting-list-results/113635/3 "2007-09-03T09:33:45Z")

</div>

Kumar: Not sure how this helps with limiting the results. “WHERE  
LIKE …” isn’t valid SQL either.

Cass: Stack trace shows line 24 to be the problem. The controller code  
you posted is syntactically valid ruby/rails (except that you should  
just do :limit =\> 5 rather than “5”) so it’s hard to tell why you’re  
getting that error. Which line is line 24?

On Sep 3, 2:09 am, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![myowntribe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a88e4f/32.png) [@myowntribe](https://www.ruby-forum.com/u/myowntribe)\
**Post date:** [September 3, 2007, 9:44am UTC](https://www.ruby-forum.com/t/query-problem-limiting-list-results/113635/4 "2007-09-03T09:44:49Z")

</div>

unknown wrote:

> Kumar: Not sure how this helps with limiting the results. “WHERE  
> LIKE …” isn’t valid SQL either.
> 
> Cass: Stack trace shows line 24 to be the problem. The controller code  
> you posted is syntactically valid ruby/rails (except that you should  
> just do :limit =\> 5 rather than “5”) so it’s hard to tell why you’re  
> getting that error. Which line is line 24?
> 
> On Sep 3, 2:09 am, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Hi Kumar,

Thanks for the reply, I tried :limit =\> 5 too but it still returns the  
same error. Just not able to figure out why this is occurring…

Cheers

Cass

---

<div class="post-metadata">

**Author:** ![myowntribe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a88e4f/32.png) [@myowntribe](https://www.ruby-forum.com/u/myowntribe)\
**Post date:** [September 3, 2007, 9:52am UTC](https://www.ruby-forum.com/t/query-problem-limiting-list-results/113635/5 "2007-09-03T09:52:47Z")

</div>

Do you have your has\_many :friends in the User model? My thought is  
that you may be mistakenly calling Enumerable#find (which takes 1  
argument) rather than AR::Base#find (which takes 2).

The rest of the stack trace should show you whether or not  
AR::Base#find is being called.

On Sep 3, 2:46 am, Cass A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![myowntribe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a88e4f/32.png) [@myowntribe](https://www.ruby-forum.com/u/myowntribe)\
**Post date:** [September 3, 2007, 9:46am UTC](https://www.ruby-forum.com/t/query-problem-limiting-list-results/113635/6 "2007-09-03T09:46:33Z")

</div>

Cass A. wrote:

> unknown wrote:
> 
> > Kumar: Not sure how this helps with limiting the results. “WHERE  
> > LIKE …” isn’t valid SQL either.
> > 
> > Cass: Stack trace shows line 24 to be the problem. The controller code  
> > you posted is syntactically valid ruby/rails (except that you should  
> > just do :limit =\> 5 rather than “5”) so it’s hard to tell why you’re  
> > getting that error. Which line is line 24?
> > 
> > On Sep 3, 2:09 am, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> Hi Kumar,
> 
> Thanks for the reply, I tried :limit =\> 5 too but it still returns the  
> same error. Just not able to figure out why this is occurring…
> 
> Cheers
> 
> Cass

By the way, Line #24 is

@friends = @user.friends.find(:all,  
:limit =\> “5”)

Cheers Cass

---

<div class="post-metadata">

**Author:** ![myowntribe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a88e4f/32.png) [@myowntribe](https://www.ruby-forum.com/u/myowntribe)\
**Post date:** [September 3, 2007, 10:01am UTC](https://www.ruby-forum.com/t/query-problem-limiting-list-results/113635/7 "2007-09-03T10:01:51Z")

</div>

Cass A. wrote:

> Rein H. wrote:
> 
> > Do you have your has\_many :friends in the User model? My thought is  
> > that you may be mistakenly calling Enumerable#find (which takes 1  
> > argument) rather than AR::Base#find (which takes 2).
> > 
> > The rest of the stack trace should show you whether or not  
> > AR::Base#find is being called.
> > 
> > On Sep 3, 2:46 am, Cass A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> Hi Rein,
> 
> Thanks for your reply, am using has\_many\_friendships plugin, may be  
> this is the reason? Could you please let me know how to tackle this  
> issue?
> 
> Cheers
> 
> Cass

Hi Rein,

Yes I do have has\_many\_friends in my user model

Cass

---

<div class="post-metadata">

**Author:** ![myowntribe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a88e4f/32.png) [@myowntribe](https://www.ruby-forum.com/u/myowntribe)\
**Post date:** [September 3, 2007, 10:00am UTC](https://www.ruby-forum.com/t/query-problem-limiting-list-results/113635/8 "2007-09-03T10:00:31Z")

</div>

Rein H. wrote:

> Do you have your has\_many :friends in the User model? My thought is  
> that you may be mistakenly calling Enumerable#find (which takes 1  
> argument) rather than AR::Base#find (which takes 2).
> 
> The rest of the stack trace should show you whether or not  
> AR::Base#find is being called.
> 
> On Sep 3, 2:46 am, Cass A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Hi Rein,

Thanks for your reply, am using has\_many\_friendships plugin, may be  
this is the reason? Could you please let me know how to tackle this  
issue?

Cheers

Cass
