Okay I’ve been working on a little biding system. In my model I have
class Item < ActiveRecord::Base
has_many :bids
def highest_bid @bid = 0
self.bids.each do |bid|
if @bid == nil @bid = bid.max
else
if bid.max > @bid @oldbid,@bid = @bid,bid.max
end
end
end
if @oldbid == 0
“#{@bid} - #{@oldbid+1} = #{@bid -= @oldbid+1}”
else
dif = @bid - @oldbid @bid -= dif
end
end
end
It’s kinda in debug mode as you can see…
But, @oldbid is 0 when there are two bids… I don’t know if it’s
because of the order they come in from SQL or what also that is a flaw
in the system so can I make it return them in a less to higher form?
It’s kinda in debug mode as you can see…
But, @oldbid is 0 when there are two bids… I don’t know if it’s
because of the order they come in from SQL or what also that is a flaw
in the system so can I make it return them in a less to higher form?
I’m afraid I’m not fully following the logic of your highest_bid
method, but you could probably do it more easily like this:
(I’m assuming here that “amount” is the column with the bid amount,
but if not, you’d have to change it.)
David
–
“To fully realize the potential of Rails, it’s crucial that you take
the time to fully understand Ruby–and with “Ruby for Rails” David
has provided just what you need to help you achieve that goal.”
– DAVID HEINEMEIER HANSSON, in the foreword to RUBY FOR RAILS.
Complete foreword & sample chapters at Ruby for Rails!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.