[Rails] Re: Help with ruby query!

2008-12-04 Thread Jay Mark
Thanks for the info guys. Now I am getting this error coming from the author's model: syntax error, unexpected tASSOC, expecting ')' This is what I have in author's class class Author ActiveRecord::Base has_many :books def author_age Author.find :all, (:conditions = [age = ?,

[Rails] Re: Help with ruby query!

2008-12-04 Thread Frederick Cheung
On 4 Dec 2008, at 14:28, Jay Mark wrote: class Author ActiveRecord::Base has_many :books def author_age Author.find :all, (:conditions = [age = ?, params[:authors]]) end end What I want to do is to display all author's name base on the selected age. please, What is wrong

[Rails] Re: Help with ruby query!

2008-12-04 Thread Jay Mark
Thanks a lot Mr. Fred. Now, I am having trouble with displaying the query result on authors\show.html I am having problems referencing the returned object and getting the two columns displayed. The error is: You have a nil object when you didn't expect it! I have this in my model: class

[Rails] Re: Help with ruby query!

2008-12-04 Thread Thorsten Müller
% @results.each do |result| % // I am not sure if this is right! tr td%=h @result.name %/td td%=h @result.age %/td /tr should be % @results.each do |result| % // I am not sure if this is right! tr td%=h result.name %/td td%=h result.age %/td /tr % end %

[Rails] Re: Help with ruby query!

2008-12-04 Thread Jay Mark
I made those changes, but I am still getting this error: You have a nil object when you didn't expect it! It is pointing to the line with the loop: % @results.each do |result| My model look like this: class Author ActiveRecord::Base has_many :books def author_age @results = Author.find

[Rails] Re: Help with ruby query!

2008-12-04 Thread Thorsten Müller
It is pointing to the line with the loop: % @results.each do |result| So for one reason or another @results is nil Most likely your query doesn't return any records. (btw: you better name that @authors instead of @results for readablity) So what is in params[:authors] ? Where does this param

[Rails] Re: Help with ruby query!

2008-12-04 Thread Jay Mark
The problem could be the query because when I search for one record, it works. So, this works fine without the query and the loop. tr td width=20%p align=centeribAuthor Name/b/i/td td width=20%p align=centeribAge/b/i/td /tr tr td%=h @author.name %/td td%=h @author.age %/td /tr % end %

[Rails] Re: Help with ruby query!

2008-12-04 Thread Hassan Schroeder
On Thu, Dec 4, 2008 at 11:28 AM, Jay Mark [EMAIL PROTECTED] wrote: The problem could be the query because when I search for one record, it works. In SQL, the query will be: SELECT name, age FROM authors WHERE age = 'the selected age' // the value, not the id of the selected age. So

[Rails] Re: Help with ruby query!

2008-12-03 Thread Teedub
I think you can find that answer here: http://railscasts.com/episodes/3-find-through-association On Dec 3, 7:43 pm, Jay Mark [EMAIL PROTECTED] wrote: I am using Rails 2.0.2 with mysql database I have two tables: book and author Table book has 3 columns: id, isbn, and title Table author

[Rails] Re: Help with ruby query!

2008-12-03 Thread Ryan Bigg
Also http://guides.rails.info/finders.html - Ryan Bigg Freelancer http://frozenplague.net On 04/12/2008, at 3:53 PM, Teedub wrote: I think you can find that answer here: http://railscasts.com/episodes/3-find-through-association On Dec 3, 7:43 pm, Jay Mark [EMAIL PROTECTED]