On 8 Dec 2008, at 16:30, Jay Mark wrote:

>
> I am using Rails 2.0.2 with mysql database
> I am getting this error when running a query with Find_by_sql:
>
> "wrong number of arguments (0 for 1)"
>
> Here are my queries:
>
> @authors = Author.find_by_sql["SELECT * FROM authors WHERE name = ?',
> name"]
> Also
> @books = Books.find_by_sql["SELECT * FROM books where title IN( SELECT
> title FROM authors where name = ?', name)"]
>
>
> I am passing in 'name' as a parameter and the URL shows the right
> parameter.
>
> Is the syntax of my queries correct?  What can cause this error?
> I use partial form and I still get the error.
>
Your syntax isn't right in two ways. You need a space before the [ or  
ruby thinks that you want to call the find_by_sql methods with no  
arguments and then call the [] method on the result, and seconly  
what's in that array isn't right,

@authors = Author.find_by_sql["SELECT * FROM authors WHERE name = ?',  
name"]

should be

@authors = Author.find_by_sql ["SELECT * FROM authors WHERE name = ?",  
name]

and arguably you shouldn't be using find_by_sql at all here,

@authors = Author.find_all_by_name name

would work just fine

Fred
> Please help!!!!
>
> Cypray
> -- 
> Posted via http://www.ruby-forum.com/.
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to