[Rails] wrong number of arguments (2 for 1)
Jean-François
jf.web3 at gmail.com
Tue Apr 11 13:08:29 GMT 2006
Hello Paul,
> I'd like to find all my departments that match a permalink passed
> from the url. The department must also match a particular category,
> also passed through the url.
>
> I have written the following code. But unfortunatley I get an error
> "wrong number of arguments (2 for 1)"
>
> category = params[:category]
> department = params[:department]
>
> @departments = Department.find(:all, :conditions => ["permalink = ?",
> department])
> @department = @departments.find(:all, :conditions => ["category = ?", category])
@departments is an array of Department objects created by
the class method Department#find.
In the second line, since @departments is an array, you are using
Enumerable#find which require 0 or 1 argument and 1 block.
So that's not the find method you want to use, and that's not the
right way to use Enumerable#find as well :)
so you'd better do :
@departments = Department.find(:all,
:conditions => ["permalink = :department AND category = :category",
params ])
-- Jean-François.
--
À la renverse.
More information about the Rails
mailing list