Forum: Ruby on Rails accepting and passing args to find

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E1aec364a0b104dbb2758a93cbab57b4?d=identicon&s=25 Ryan Eibling (Guest)
on 2006-02-15 23:00
I have a method that I want to accept args like the "find" method does
and I need to pass those args along to a find call.

# in controller action:

@projects = Project.find_allowed(session[:user], :order => "name")

# start of the model method:

def self.find_allowed(owner, *args)
  projects = self.find_all(args)

No matter how I try to pass those args along I get something like the
following error:

ActiveRecord::StatementInvalid: Mysql::Error: #42S22Unknown column
'ordername' i
n 'where clause': SELECT * FROM projects WHERE (ordername)

I've tried self.find_all(*args), I've tried doing various conversions
and nothing seems to work. I'm sure I'm missing something simple, I just
can't find what it is. Thanks for any help anybody can offer.
132a94ca65959bda6c74fae54bff2425?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-02-16 00:57
(Received via mailing list)
On Feb 15, 2006, at 2:00 PM, Ryan Eibling wrote:

>   projects = self.find_all(args)
>   ...

def self.find_allowed(owner, *args)
     projects = self.find_all(*args)

Since you are *splatting the args ito the method, you need to *splat
them into find. then it will work as you want it to.


-Ezra Zygmuntowicz
Yakima Herald-Republic
E1aec364a0b104dbb2758a93cbab57b4?d=identicon&s=25 Ryan Eibling (Guest)
on 2006-02-16 13:14
Ezra Zygmuntowicz wrote:

> def self.find_allowed(owner, *args)
>      projects = self.find_all(*args)

Thanks, but that was one of the things I already tried that didn't work.
I don't know exactly how find_all is implemented, but I discovered that
when I change it to:

self.find(:all, *args) works. Strange.
8e44c65ac5b896da534ef2440121c953?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-02-16 16:49
(Received via mailing list)
On Feb 16, 2006, at 4:14 AM, Ryan Eibling wrote:

> self.find(:all, *args)
> works. Strange.

Yeah you're right. I didn't use find_all in my test as I always use
find :all . So I shouldn't have assumed find_all worked.

-Ezra Zygmuntowicz
Yakima Herald-Republic Newspaper
This topic is locked and can not be replied to.