I is possible to do calculations on a virtual attribute... such as
sum, or count

I tried using the same as I would on a DB column but of course that
doesn't work. ie.  Pricelist.sum(:cyberguide)

I have a table with 2 fields, one with a price and the other with a
condition then have a virtual attribute which does a calculation:

  def cyberguide
    if condition <= 2
      [price.pricehigh]
    elsif condition == 3
      [price.pricehigh * 0.9]
    elsif condition == 4
      [price.pricehigh * 0.5]
    elsif condition == 5
      [price.pricehigh * 0.25]
    elsif condition == 6
      [price.pricehigh * 0.2]
    else
      [price.pricehigh * 0.15]
    end
  end

It works perfectly for individual functions, but how would a sum the
virtual attribute?

Thanks

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