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
Related
I am trying to unzip a file in my Spree plugin.
Defined the unzipping method in a module which looks like this.
module ImportImages
class Zipper
def self.unzip(zip, unzip_dir, remove_after = false)
Zip::File.open(zip) do |zip_file|
zip_file.each do |f|
f_path=File.join(unzip_dir, f.name)
FileUtils.mkdir_p(File.dirname(f_path))
zip_file.extract(f, f_path) unless File.exist?(f_path)
end
end
FileUtils.rm(zip) if remove_after
end
end
end
I have included the rubyzip gem in my Gemfile.
gem 'rubyzip'
gem 'zip-zip'
When trying to run it, I am getting the following error.
NameError - uninitialized constant ImportImages::Zipper::Zip:
I have tried every solution provided in stackoverflow and other sites. I tried downgrading the version of rubyzip which is 1.2.0 now and add require 'zip' or require 'zip/zip'. Both returned load error.
I have try adding require 'zip/filesystem' to the class. But got
LoadError - cannot load such file -- zip/zipfilesystem
Any solution for this?
Include rubyzip in gem file in this way:
gem 'rubyzip', require: 'zip'
See this question
It's looking for a nested Constant. Change line Zip::File.open(zip) do |zip_file| with below:
::Zip::File.open(zip) do |zip_file|
It should work.
Also make sure you require rubygem/bundle setup. Though in spree it should've already been done.
Babar's answer is correct, but you also need to add require 'zip' in application_controller.rb
Im trying to install Kaminari pagination on rails 3 with adminpanel RailsAdmin, but I get this error:
NoMethodError in ShowsController#
undefined method `page' for # < ActiveRecord::Relation:0xaadc8d4>
Do you also have the gem "will_paginate" in use?
Check the file Gemfile.lock to see if you have this gem in use as well:
grep will_paginate Gemfile.lock
If that's the case, all you have to do is to create the file "config/initializers/kaminari.rb" and write this content on the file:
Kaminari.configure do |config|
config.page_method_name = :per_page_kaminari
end
that should fix the issue
In my case I forgot to add the kaminari gem to my Gemfile :facepalm:
I'm using the google-api-client gem (gem google-api-client, '0.4.1' in my Gemfile). The following code caused the error uninitialized constant MyController::Google:
class MyController < ApplicationController
def index
#client = Google::APIClient.new
end
end
Specifying ::Google::APIClient didn't help, the error then said uninitialized constant Google.
Simply adding a require 'google/api_client' at the top of the file made this go away, so it seems there's something wrong in how auto-loading is being done. Not sure what's going on here exactly, specifying the gem in my Gemfile should have automatically required the gem, right? I have restarted the rails server btw.
Try adding a :require => 'google/api_client' where you specify the google api client gem in the Gemfile
gem 'google-api-client', :require => 'google/api_client'
This tells bundler that the correct way to require the gem 'google-api-client' is to require 'google/api_client'
I have ruby and my gems installed in my home directory using rvm. 'require RMagick' works from the console and irb, but not from within my Rails app. I have the gem listed in my Gemfile.
require 'RMagick'
class PetsController < ApplicationController
def image
image = Image.new(image_path("base/Base.png"))
#image = Pet.composite(0, '4a4a4a')
#response.headers["Content-type"] = image.mime_type
render :text => image.to_blob
end
end
If I remove the require from my controller, I get
uninitialized constant PetsController::Image
I also have tried require 'RMagick' in boot.rb, and by referring to the Image object using Magick::Image (which gives me uninitialized constant PetsController::Magick.
What am I doing wrong?
Solved it! Restarting the server fixed it. I guess I hadn't restarted the server when I added rmagick to my gemfile.
Is it possible that you are running the rails app with another user than the one that has the RMagick gem installed?
I have a very simple controller:
require 'net/ssh'
class MyController < ApplicationController
def foo
render :text => 'bar'
end
end
But when I request http://server:3000/my/foo I get:
MissingSourceFile in MyController#foo
no such file to load -- net/ssh
The gem is installed
> gem list net-ssh
*** LOCAL GEMS ***
net-ssh (2.0.11)
Also, I tried require 'net/ssh' in IRB, and it works.
MyController works fine on Windows, but fail on Ubuntu.
What can be wrong?
In a project I am working on we have used the config/environment.rb file to hold the gem require stuff. So
Rails::Initializer.run do |config|
# ...
config.gem 'net-ssh'
config.gem 'daemons'
config.gem 'slave'
config.gem 'vpim'
config.gem 'json'
# ...
end
I think you will require 'net-ssh' rather than 'net/ssh'. However we did run into a problem where have a hyphen in the name of the gem led to failures. Then we had to do
config.gem 'Ruby-IRC', :lib => 'IRC'
so that version maybe required for you. So that would be
config.gem 'net-ssh', :lib => 'net/ssh'
in case of rails 3.0
this solution if OK.
add this in the yourapp/Gemfile,
gem 'net-ssh
This may help:
Rails Gem Dependencies and Plugin Errors
This is also worth watching:
Railscasts: Gem Dependencies
In my case, since it's a stand alone ruby app, I only needed to require rubygems.
You can also use Dr Nic's ''gemsonrails'' and load vendored gems as plugins, check:
http://gemsonrails.rubyforge.org
I think, the original problem was that I used normal user instead of root:
$ gem install net-ssh
WARNING: Installing to ~/.gem since /usr/lib/ruby/gems/1.8 and
/usr/bin aren't both writable.
WARNING: You don't have /home/alex/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
So, I guess, rails could not find this gem.