Reputation: 83
I am a total noob at ruby on rails so what I am trying to do is multiply the value of each row in two columns together and store it in a new object. I know how I would do it in mysql but when I do something like this in my .erb file
@ordertotals = Orderline.where(:id => @orderparts.id).sum("quantity * price")
I get this error
undefined method `where' for #<Class:0x7f843ff72ce8>
I have been looking around and cant find an explanation of how to actually do a where search that I understand. I have seen that some things actually need to go in the model file but I dont know where to begin on how to define that in the model or call it passing it the needed info from the .erb file, can anyone explain this to me?
class Orderline < ActiveRecord::Base
belongs_to :order
end
Upvotes: 0
Views: 1737
Reputation: 10996
where
was added only in Rails 3.x. Since you are on Rails 2.3.x, you have to use the old syntax.
@ordertotals = Orderline.find(:all, :conditions => ["id = ?", @orderparts.id], :select => "quantity * price as total_price")
I hope I have got the syntax right. Don't have rails 2 to test it.
Upvotes: 2
Reputation: 8058
Syntax for Rails 2.3.x
@ordertotals = Orderline.all(:conditions=>"id='#{@orderparts.id}'",:select=>"quantity * price as PRODUCT")
Upvotes: 0