[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Bad query?

raffir

7/24/2006 5:03:00 AM

I have a find() query inside a for loop. Basically, I want the loop to
go through all elements in User.accounts and find all elements in
Accounts that have the same name as each element (to see other users
who have accounts with the same name).

Right now my code is as follows:

<table>
<%@session['user'].accounts.each do |i| %>
<%Accounts.find(:all, :conditions => ["coursenumber LIKE ?",
"%#{i.coursenumber}%"]).each do |account| %>

<tr>
<td><%= account.coursename %></td>
<td><%= account.coursenumber %></td>
<td><%= account.user_id%></td>
<td><%= account.first_name%> <%= account.last_name%></td>
<td><%= link_to 'Show', :controller=>'user', :action=>'userdetails',
:id=> account.user_id %></td>
</tr>

<%end%>
<% end %>
</table>

This has the effect of outputting every single account in the Accounts
table. I'd like to restrict it to just outputting those accounts with
the same course name/number as each one of the User's.


Thanks a lot,

- Raffi.

1 Answer

Jano Svitok

7/24/2006 9:55:00 AM

0

Try to fiddle with the condition... what are your course numbers like?
J.

On 7/24/06, raffir@gmail.com <raffir@gmail.com> wrote:
> I have a find() query inside a for loop. Basically, I want the loop to
> go through all elements in User.accounts and find all elements in
> Accounts that have the same name as each element (to see other users
> who have accounts with the same name).
>
> Right now my code is as follows:
>
> <table>
> <%@session['user'].accounts.each do |i| %>
> <%Accounts.find(:all, :conditions => ["coursenumber LIKE ?",
> "%#{i.coursenumber}%"]).each do |account| %>
>
> <tr>
> <td><%= account.coursename %></td>
> <td><%= account.coursenumber %></td>
> <td><%= account.user_id%></td>
> <td><%= account.first_name%> <%= account.last_name%></td>
> <td><%= link_to 'Show', :controller=>'user', :action=>'userdetails',
> :id=> account.user_id %></td>
> </tr>
>
> <%end%>
> <% end %>
> </table>
>
> This has the effect of outputting every single account in the Accounts
> table. I'd like to restrict it to just outputting those accounts with
> the same course name/number as each one of the User's.
>
>
> Thanks a lot,
>
> - Raffi.
>
>
>