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="center"><i><b>Author Name</b></i></td>
 <td width="20%"><p align="center"><i><b>Age</b></i></td>
 </tr>



 <tr>

 <td><%=h @author.name %></td>
 <td><%=h @author.age %></td>
 </tr>
<% end %>

But this returns one 'Name' for the selected 'age'. That means it is 
returning the name that is in the same row with the selected age, that 
is, having same id.

In the database, there are several names with same age. So, what I want 
is a query that will return all names with age value equal to the value 
of the selected age and not the id of the selected age.

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, I need help with a query that will return all the names with the 
selected age, and also the proper way to display those names and the age 
on author\show.html

cypray





Thorsten Mueller wrote:
>> 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 come from and does it contain an age?
> After all, that's what you ask Rails to search for in
> @results = Author.find :all, :conditions => ["age = ?", params
> [:authors]]
> 
> So if for example params[:authors] would contain an authors id or
> name (as the name suggests) then it wouldn't find anything.
> 
> You could easily debug this with something like:
> @results = Author.find :all, :conditions => ["age = ?", params
> [:authors]]
> logger.info "RESULT: [EMAIL PROTECTED]"
> Then you would find the number of found records in development.log
> (Where btw you could see, which params where sent to your controller)

-- 
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 rubyonrails-talk@googlegroups.com
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