I know that I might have too much logic in my view, so I’m wondering how I can include it in my controller:
Controller:
def purchasers
@deal = Deal.find(params[:id])
@pl = @deal.purchases
end
View:
<% title "List Of Purchases" %>
Total Purchases: <%= @pl.count %><BR><BR>
<%
@pl.each do |p|
u = User.find(p.user_id)
%>
<%= u.email %><BR>
<%
end
%>
I’d suggest that you remove the call to
User.findinside the view code.It looks like you’re looking up the user from the
user_idstored in the purchase. Why not in the model use:And then in the view code:
Hope this helps.