Forum: Ruby on Rails find_by_sql sanity check

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dave A. (Guest)
on 2007-01-20 08:18
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
Jeremy McAnally (Guest)
on 2007-01-20 08:20
(Received via mailing list)
@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> wrote:
>           where r.user_id = f.friend_id and f.user_id = ?
> Dave
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>


--
My free Ruby e-book:
http://www.humblelittlerubybook.com/book/

My blogs:
http://www.mrneighborly.com/
http://www.rubyinpractice.com/
Dave A. (Guest)
on 2007-01-20 08:23
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> wrote:
>>           where r.user_id = f.friend_id and f.user_id = ?
>> Dave
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>> >
>>
>
>
> --
> My free Ruby e-book:
> http://www.humblelittlerubybook.com/book/
>
> My blogs:
> http://www.mrneighborly.com/
> http://www.rubyinpractice.com/
Jeremy McAnally (Guest)
on 2007-01-20 08:43
(Received via mailing list)
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> wrote:
> >
> >> Dave
> > http://www.humblelittlerubybook.com/book/
>
--
My free Ruby e-book:
http://www.humblelittlerubybook.com/book/

My blogs:
http://www.mrneighborly.com/
http://www.rubyinpractice.com/
Dave A. (Guest)
on 2007-01-20 18:42
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> wrote:
This topic is locked and can not be replied to.