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
in controller write like this
@friend = User.find(params[:id])
@friends = User.find(:all, :conditions => ["LIKE ?", <what u want
to find>])
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, “[email protected]” [email protected]
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, “[email protected]” [email protected]
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
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. [email protected]
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, “[email protected]” [email protected]
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
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. [email protected]
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
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. [email protected]
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