如果百分比发生变化,我该如何才能进行此展示?

时间:2011-06-02 20:50:24

标签: ruby

我被困在这里:

puts "#{percent_finished.round}% uploading complete" ? if/unless ...

2 个答案:

答案 0 :(得分:1)

如果percent_finished是ActiveRecord模型的一部分,您实际上只需拨打percent_finished_changed?即可。

例如:

puts "#{percent_finished.round}% uploading complete" if percent_finished_changed?

以下是一些文档:

http://ar.rubyonrails.org/classes/ActiveRecord/Dirty.html

答案 1 :(得分:1)

这是一个命令行工具吗?

last_percent = nil
upload_loop do
    # ...
    percent_rounded = percent_finished.round
    puts "#{percent_rounded}% uploading complete" if percent_rounded != last_percent
    last_percent = percent_rounded
end