Thanks for your help Fred. The wrong number of argument problem is gone.
The queries are still not working.
Using find_all_by_name give me "method not found error"
This one below returns no data but gives no error. But it works fine
when I put it in mysql directly.
@authors = Author.find_by_sql ["SELECT * FROM authors WHERE name = ?",
'name']
Also passing it in as author[:name] returns no data but gives no error,
just empty rows
@authors = Author.find_by_sql ["SELECT * FROM authors WHERE name = ?",
'author[:name]']
Without the single quote ('') around the 'name', I get "undefined local
variable" error.
Does any one know what is wrong with my query?
Also Rails is rejecting the syntax of the subselect below:
@books = Books.find_by_sql ["SELECT * FROM books where title IN( SELECT
title FROM authors where name = ?", 'name')]
It is not accepting '(' or '[' to enclose the inner SELECT
I have tested this also in mysql and it works fine.
Does any one know the correct syntax for a subselect in Rails?
Thanks
Cypray.
Frederick Cheung wrote:
> On 8 Dec 2008, at 16:30, Jay Mark wrote:
>
>> 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
--
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
-~----------~----~----~----~------~----~------~--~---