Jay Mark wrote: > Priya Buvan wrote: >> @books = Book.find(:all, :joins=>"books inner join authors as a on >> books.title=a.name", :conditions => ['name LIKE ? ', >> '%'+params[:author][:name]+'%']) >> >> >> try with the above code > > > > I put the code in Authors Controller as it is, and I get nil object > error. > Since I am using @authors in my view, I changed the @books to @authors. > That gives no error but it returned empty row. > > The selection of 'name' takes place in view\author\index.html and the > result of the query will be displayed in view\author\show.html > I think I have to return @authors for <% @authors.each do |geogr| %> > to work in the view, unless their is a different way to do it with > @books > > Cypray
I changed the loop to <% @books.each do |book| %> This code is still giving empty row: @books = Book.find(:all, :joins=>"books inner join authors as a on books.title=a.name", :conditions => ['name LIKE ? ', '%'+params[:author][:name]+'%']) But the problem is resolved now with this code: @books = Books.find_by_sql ["SELECT * FROM books WHERE title IN (SELECT title FROM authors WHERE name = ?)", params[:author][:name]] Thanks for your help guys. 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 -~----------~----~----~----~------~----~------~--~---

