# Find\_by\_sql sanity check

**URL:** <https://www.ruby-forum.com/t/find-by-sql-sanity-check/82742>\
**Category:** Rails\
**Created:** [January 20, 2007, 7:18am UTC](https://www.ruby-forum.com/t/find-by-sql-sanity-check/82742 "2007-01-20T07:18:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveamos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@daveamos](https://www.ruby-forum.com/u/daveamos)\
**Post date:** [January 20, 2007, 7:18am UTC](https://www.ruby-forum.com/t/find-by-sql-sanity-check/82742/1 "2007-01-20T07:18:01Z")

</div>

Hi everyone,

I’m doing a find\_by\_sql to do a paginated list of a users’ friends’  
recipes, but I keep getting an error with my find\_by\_sql line (Wrong  
number of arguments 0 for 1). Is there anything I’m obviously doing  
wrong?

```
    query = "select r.*
      from recipes r, friends_users f
      where r.user_id = f.friend_id and f.user_id = ?
      order by r.date_added desc
      limit #{offset}, #{per_page}"
    @friends_recipes = Recipe.find_by_sql[query, params[:id]]

```

Let me know if it’s something simple I’ve missed. I can’t figure it  
out!

Thanks a lot,

Dave

---

<div class="post-metadata">

**Author:** ![daveamos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@daveamos](https://www.ruby-forum.com/u/daveamos)\
**Post date:** [January 20, 2007, 7:20am UTC](https://www.ruby-forum.com/t/find-by-sql-sanity-check/82742/2 "2007-01-20T07:20:56Z")

</div>

@friends\_recipes = Recipe.find\_by\_sql[query, params[:id]]

should be…

@friends\_recipes = Recipe.find\_by\_sql(query, params[:id])

I believe…

–Jeremy

On 1/20/07, Dave A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> where r.user_id = f.friend_id and f.user_id = ?
> 
> ```
> 
> Dave
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
My free Ruby e-book:  
[http://www.humblelittlerubybook.com/book/](http://www.humblelittlerubybook.com/book/)

My blogs:

> **[Site not found · DreamHost](http://www.mrneighborly.com/)**
>
> The owner of this domain has not yet uploaded their website.

[http://www.rubyinpractice.com/](http://www.rubyinpractice.com/)

---

<div class="post-metadata">

**Author:** ![daveamos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@daveamos](https://www.ruby-forum.com/u/daveamos)\
**Post date:** [January 20, 2007, 7:23am UTC](https://www.ruby-forum.com/t/find-by-sql-sanity-check/82742/3 "2007-01-20T07:23:03Z")

</div>

I tried that as well, and I get an error (Arguments 2 for 1). I can’t  
seem to figure out how to give it the right number of arguments, even  
though it looks right to me! Frustrating… 🙂

Dave

Jeremy McAnally wrote:

> @friends\_recipes = Recipe.find\_by\_sql[query, params[:id]]
> 
> should be…
> 
> @friends\_recipes = Recipe.find\_by\_sql(query, params[:id])
> 
> I believe…
> 
> –Jeremy
> 
> On 1/20/07, Dave A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > ```
> > where r.user_id = f.friend_id and f.user_id = ?
> > 
> > ```
> > 
> > Dave
> > 
> > –  
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > >
> 
> –  
> My free Ruby e-book:  
> [http://www.humblelittlerubybook.com/book/](http://www.humblelittlerubybook.com/book/)
> 
> My blogs:  
> [http://www.mrneighborly.com/](http://www.mrneighborly.com/)  
> [http://www.rubyinpractice.com/](http://www.rubyinpractice.com/)

---

<div class="post-metadata">

**Author:** ![daveamos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@daveamos](https://www.ruby-forum.com/u/daveamos)\
**Post date:** [January 20, 2007, 5:42pm UTC](https://www.ruby-forum.com/t/find-by-sql-sanity-check/82742/4 "2007-01-20T17:42:11Z")

</div>

Thank you, it works perfectly!

Jeremy McAnally wrote:

> Oh _smack_
> 
> @friends\_recipes = Recipe.find\_by\_sql([query, params[:id]])
> 
> That should work I thnk. It’s too late to think. 😉
> 
> –Jeremy
> 
> On 1/20/07, Dave A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

---

<div class="post-metadata">

**Author:** ![daveamos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@daveamos](https://www.ruby-forum.com/u/daveamos)\
**Post date:** [January 20, 2007, 7:43am UTC](https://www.ruby-forum.com/t/find-by-sql-sanity-check/82742/5 "2007-01-20T07:43:57Z")

</div>

Oh _smack_

@friends\_recipes = Recipe.find\_by\_sql([query, params[:id]])

That should work I thnk. It’s too late to think. 😉

–Jeremy

On 1/20/07, Dave A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > Dave  
> > > [http://www.humblelittlerubybook.com/book/](http://www.humblelittlerubybook.com/book/)

–  
My free Ruby e-book:  
[http://www.humblelittlerubybook.com/book/](http://www.humblelittlerubybook.com/book/)

My blogs:

> **[Site not found · DreamHost](http://www.mrneighborly.com/)**
>
> The owner of this domain has not yet uploaded their website.

[http://www.rubyinpractice.com/](http://www.rubyinpractice.com/)
