如何在Rails中使用ruby-progressbar?

时间:2013-02-11 23:26:56

标签: ruby-on-rails ruby ruby-on-rails-3.2

我想在Rails 3.2.11中使用ruby-progressbar作为我的控制台脚本。我将gem 'ruby-progressbar'添加到Gemfile并运行bundle install

当我尝试使用它时会显示uninitialized constant ProgressBar

如果我require 'ruby-progressbar',则会显示以下错误:

LoadError: cannot load such file -- ruby-progressbar from /Users/evgenyneu/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'

1 个答案:

答案 0 :(得分:2)

宝石: https://rubygems.org/gems/ruby-progressbar

你需要写一些:

require 'progressbar'
pbar = ProgressBar.new('data processing', some_long_data_array.length)
some_long_data_array.each do |data|
  data.process 
  pbar.inc
end
pbar.finish