I want to use ruby-progressbar in Rails 3.2.11 for my console scripts. I added gem 'ruby-progressbar' to Gemfile and ran bundle install.
It shows uninitialized constant ProgressBar when I try to use it.
If I do require 'ruby-progressbar' it shows the following error:
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'
gem :
https://rubygems.org/gems/ruby-progressbar
You need write some as:
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
Related
I have the following ruby code :
require 'HTTPClient'
require 'rubygems'
require 'zip'
def self.unzip(data, dest_dir)
::Zip::File.open_buffer(data) do |fzip|
fzip.each do |entry|
path = File.join(dest_dir, entry.name)
puts "here"
FileUtils::mkdir_p(File.dirname(path))
fzip.extract(entry, path) unless File.exist?(path)
#fzip.close
end
end
end
def self.fetch_from_url(url, dest_dir)
response = HTTPClient.get(url, follows_redirect: true)
if response.status == 200
unzip(response.body, dest_dir)
else
raise 'Could not fetch files from 3scale'
end
end
url = 'link/artifactory/zip-release-local/djin/3Sroxy/1.0.5/configuration.zip'
fetch_from_url(url, "/Users/something/")
When I run this in Mac ruby 2.0.0p481 it works fine and unzips the folder, but when I run the same in centOS 6.6 in ruby 1.8.7 it fails with following :
[root#ip-10-201-90-206 ~]# sudo ruby test/ex.rb
test/ex.rb:7:in `unzip': uninitialized constant Zip::File (NameError)
from test/ex.rb:20:in `fetch_from_url'
from test/ex.rb:28
also, I've done :
gem install zip
Successfully installed zip-2.0.2
1 gem installed
Installing ri documentation for zip-2.0.2...
Installing RDoc documentation for zip-2.0.2...
As Prashant4224 stated, you need to install
gem install rubyzip
You seem to use the zip Gem...
In Gemfile you need to add. Everything else didn't work for me.
gem 'rubyzip', '>= 1.0.0'
gem 'zip-zip'
I am using ruby 2.2.1 and rails 4.2.1.
I am using following gems.
roo (2.0.1)
roo-xls (1.0.0)
rubyzip (1.1.7)
I have written a rake task as follows.
check_roo.rake
require 'rubygems'
require 'roo-xls'
require 'roo'
desc "desc"
task :check_roo => :environment do |task, args|
xlsx = Roo::Excelx.new("#{Rails.root}/v15_Data.xlsx")
end
Output for bundle exec rake check_roo:
NameError: uninitialized constant Roo::Excelx::Zip
/home/abhimanyu/.rvm/gems/ruby-2.2.1#newerp/gems/roo-2.0.1/lib/roo/excelx.rb:412:in `process_zipfile'
/home/abhimanyu/.rvm/gems/ruby-2.2.1#newerp/gems/roo-2.0.1/lib/roo/excelx.rb:100:in `initialize'
/home/abhimanyu/Documents/projects/abc/lib/tasks/check_roo.rake:9:in `new'
/home/abhimanyu/Documents/projects/abc/lib/tasks/check_roo.rake:9:in `block in <top (required)>'
But when I run the following command in rails console it works fine.
xlsx = Roo::Excelx.new("#{Rails.root}/v15_Data.xlsx")
Output:
<#Roo::Excelx:320135634 #tmpdirs #tmpdir #filename #comments_files #rels_files #sheet_files #workbook #sheet_names #sheets #styles #shared_strings #sheets_by_name #options #cell #cell_type #cells_read #first_row #last_row #first_column #last_column #header_line>
Not able to understand why the same command works in console but not inside a rake file.
Any help would be appreciated. Thanks in advance.
I want to test my RESTful resource in Rails:
require 'rubygems'
require 'activeresource'
class Event < ActiveResource::Base
self.site = "http://localhost:3000"
end
events = Event.find(:all)
puts events.map(&:name)
I have installed gem:
gem install activeresource
But when I launch my code I get the error message:
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- activeresource (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from service.rb:2:in `<main>'
How can I require ActiveResource?
There is a typo in your require, the following is the correct one:
require 'active_resource'
With bunder you can do this just with
gem "activeresource", require: "active_resource"
Normally gems requires file with name equal to gem’s name, with gem "foo" :require => bar syntax you can specify different file to be included by default.
i think you can do it this way:
require 'rubygems'
gem 'activeresource'
require 'active_resource'
You can also specify which version of activeresource you want by
gem 'activeresource', '=3.0.7'
for example. Or you can omit this line completely, but this way it's cleaner... and it makes sure that you get the right version.
Hope this helps, NoICE
gem install rubyoverflow
irb
> require 'rubyoverflow'
=> true
But:
require 'rubyoverflow'
include Rubyoverflow
class QuestionsController < ApplicationController
def question_by_tag
ruby_q = Questions.retrieve_by_tag('ruby')
Get error:
LoadError in
QuestionsController#question_by_tag no
such file to load -- rubyoverflow
Rails.root:
D:/artefacts/dev/projects/stack
app/controllers/questions_controller.rb:1:in
`'
This error occurred while loading the
following files: rubyoverflow
Is there any special rules to import moduled in the controller?
why do you use both require and include? include Rubyoverflow will be enough
UPD
For gem you should add it into your Gemfile (Rails 3.x) or config/environment.rb (Rails 2.x)
# Gemfile
gem "rubyoverflow"
# environment.rb
config.gem "rubyoverflow"
Then run bundle for Rails 3.x and rake gems:install for Rails 2.x
I have a rails 2.3.4 app that I'd like to extend with omniauth (0.1.5). When I install omniauth gem using rvm and place require 'omniauth' in the config.rb file I get the following error:
`gem_original_require': no such file to load -- omniauth (MissingSourceFile)
The tutorials suggest using putting it in the gemfile but I am using rails 2.
When I 'gem list' omniauth is available however.
This has taken a couple of (hair-pulling) days and I am not sure how to proceed.
Am I placing the require in the correct place or is there somewhere else I could put it (aside form the obvious :-))?
Any ideas would be great....
EDIT 1: I tried config.gem "omniauth" in your environments.rb file and got
/home/mcaulejj/explorer/config/environment.rb:10: undefined local variable or method `config' for main:Object (NameError)
EDIT 2: Using RVM I updated all gems but I am still getting the same error.....
I'm exasperated at this point.
Cheers Slothihtype
Try config.gem "omniauth" in your environments.rb file.
EDIT
As per comment,
try:
require File.join(File.dirname(__FILE__), 'boot')
#insert the following here, in your config/environment.rb
if Gem::VERSION >= "1.3.6"
module Rails
class GemDependency
def requirement
r = super
(r == Gem::Requirement.default) ? nil : r
end
end
end
end
Add require 'oa-oauth' in your environment.rb file