On 16 March 2010 15:57, Michael Pavling <[email protected]> wrote:
>> Also, is it possible to order the hash so that they appear in
>> descending order of how much of each item is in stock? In other words,
>> sort descending by the value that the following generates?
>>
>> <%=h "#{s.last.sum(&:amount_received) -
>> s.last.sum(&:amount_dispensed)}" %>
>

how about:

<%
@medicine.grouped_stocks.each_pair do |k, v|
 v.sort_by {|stock| stock.amount_on_hand}.each do |stock|
   %>
   <%= "#{stock.medicine.name} #{stock.strength} #{stock.route.name}
#{stock.amount_on_hand}" %>
   <%
 end
end
%>

not sure if that will sort ascending or descending though... if it's
the wrong way round, you can always reverse before you .each...

-- 
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.

Reply via email to