On 8 Dec 2008, at 23:36, Ryan Bigg wrote:
> > If it's coming in dynamically, wouldn't it be params[:author][:name] > or something similar? A bit hard to guess without seeing more code. D'oh of course, not sure why I wrote author[:name] Fred > > ----- > Ryan Bigg > Freelancer > http://frozenplague.net > > > > > > > > On 09/12/2008, at 9:30 AM, Frederick Cheung wrote: > >> >> >> On 8 Dec 2008, at 22:53, Jay Mark wrote: >> >>> >>> Thanks again Fred. >>> NO, I am not asking for the author whose name is the exact string >>> 'name'. >>> "Name" is the attribute or column in the authors table which has >>> name >>> values like James, John, etc. The user will select a name, say John, >>> then I am passing that name as a condition to the query. >>> After a submit button is clicked, the URL shows this: >>> http://localhost:3000/authors/show?author[name]=John&commit=Submit >>> >>> I can't stick the name value in because it has to come dynamically >>> to >>> the controller. Name is not unique in the table >>> >>> I am still looking for the correct syntax for this: >>> @authors = Author.find_by_sql ["SELECT * FROM authors WHERE name >>> = ?", >>> 'author[:name]'] >> >> Author.find_all_by_name author[:name] >> In general, whereever I wrote name in the previous suggestions you >> can >> just write author[:name] >> >> >>> >>> >>> >>> >>> and this subselect: >>> >>> @books = Books.find_by_sql ["SELECT * FROM books where title >>> IN( SELECT >>> title FROM authors where name = ?", 'name')] >>> >> >> Like I said, you've not to write it in the form >> Books.find_by_sql [some_sql_statement, author[:name]] >> >> Seems to me like you would benefit from going back to some basic ruby >> stuff. >> >> Fred >>> I can't find it in the Docs. >>> Please send me any pointers. >>> Thanks >>> >>> Cypray >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> Frederick Cheung wrote: >>>> On Dec 8, 7:31�pm, Jay Mark <[EMAIL PROTECTED]> >>>> wrote: >>>>> 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" >>>>> >>>> That should work as long as the argument you pass it exists (and >>>> as >>>> long as Author has a column called name) , but from what you say >>>> below >>>> you don't have a local variable called name. >>>> >>>>> 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 >>>>> >>>> Well you've asked for authors whose name is the exact string >>>> 'name'. >>>> Presumably you have a variable of some sort with the name you are >>>> searching for ? You should stick that in >>>> >>>> >>>>> @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: >>>>> >>>> You're closing the parens in the wrong place. what you pass to >>>> find_by_sql must be >>>> [ "A string with all the sql", all, the, substitutions, here] >>>> >>>> take a look at the examples in the docs. >>>> >>>> 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 -~----------~----~----~----~------~----~------~--~---

