# Accepting and passing args to find

**URL:** <https://www.ruby-forum.com/t/accepting-and-passing-args-to-find/68940>\
**Category:** Rails\
**Created:** [February 15, 2006, 11:00pm UTC](https://www.ruby-forum.com/t/accepting-and-passing-args-to-find/68940 "2006-02-15T23:00:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![diragor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6a8cbe/32.png) [@diragor](https://www.ruby-forum.com/u/diragor)\
**Post date:** [February 15, 2006, 11:00pm UTC](https://www.ruby-forum.com/t/accepting-and-passing-args-to-find/68940/1 "2006-02-15T23:00:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![diragor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6a8cbe/32.png) [@diragor](https://www.ruby-forum.com/u/diragor)\
**Post date:** [February 16, 2006, 12:57am UTC](https://www.ruby-forum.com/t/accepting-and-passing-args-to-find/68940/2 "2006-02-16T00:57:49Z")

</div>

On Feb 15, 2006, at 2:00 PM, Ryan E. 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.

Cheers-

-Ezra Z.  
Yakima Herald-Republic  
WebMaster

> **[yakimaherald.com | Yakima, Washington - We Tell Your Stories](https://www.yakimaherald.com/)**

509-577-7732  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![diragor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6a8cbe/32.png) [@diragor](https://www.ruby-forum.com/u/diragor)\
**Post date:** [February 16, 2006, 1:14pm UTC](https://www.ruby-forum.com/t/accepting-and-passing-args-to-find/68940/3 "2006-02-16T13:14:53Z")

</div>

Ezra Z. 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)

…it works. Strange.

---

<div class="post-metadata">

**Author:** ![diragor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6a8cbe/32.png) [@diragor](https://www.ruby-forum.com/u/diragor)\
**Post date:** [February 16, 2006, 4:49pm UTC](https://www.ruby-forum.com/t/accepting-and-passing-args-to-find/68940/4 "2006-02-16T16:49:40Z")

</div>

On Feb 16, 2006, at 4:14 AM, Ryan E. wrote:

> self.find(:all, \*args)
> 
> …it 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.

Cheers-  
-Ezra Z.  
WebMaster  
Yakima Herald-Republic Newspaper  
removed\_email\_address@domain.invalid  
509-577-7732
