no such file to load -- rack/openid - ruby-on-rails

I am working on a rails gem which depends on rack/openid. But when I require it and fire up my application I get this error
no such file to load -- rack/openid
The gem is installed
$ gem list | grep openid
rack-openid (1.3.1, 1.2.0)
ruby-openid (2.1.8)
I've seen this question but it did NOT helped a lot.
Problem with require rack/openid in Rails 3 [native require work properly]
PS: I can require it from Irb just fine

It looks like you haven't added your Gem to the Gemfile, or you haven't added rack-openid as a dependency to your gem.
When Rails starts up, it uses bundler to set up the load path to match the Gemfile.lock file, so even a gem is installed locally you won't be able to require it if it isn't listed there.
Gemfile.lock is created by bundler based on the gems listed in Gemfile and their dependencies.
Make sure the gem you're working on specifies rack-openid as a dependency in its .gemspec, and then add gem 'my-gem-name' to your applications Gemfile (replace my-gem-name with whatever your gem is actually named).

Related

How to use a specific Nokogiri version for Rails application

I'm trying to run a Rails application that I wrote a couple of years ago, however I keep getting this error when I run rails server:
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'nokogiri' (>= 1.5.9) - did find: [nokogiri-1.5.6] (Gem::LoadError)
I'm pretty confused, since I have Nokogiri v1.8.2 and v1.10.7 installed and see them under .gem/ruby/2.3.0 and /Library/Ruby/Gems/2.3.0. I don't see Nokogiri v1.5.6 though, so I'm not sure where the application is getting that from.
I tried adding
gem 'nokogiri', '~> 1.10', '>= 1.10.3'
to the Gemfile, as well as
gem 'nokogiri', '~> 1.5.6'
I'm trying to figure out if I can change the GEM_PATH, but hopefully there's another solution I'm not seeing.
Nokogiri is used by Rails, so you don't need to add it to your Gemfile, but you can update the version in your Gemfile.lock using:
bundle update nokogiri

Could not find 'ruby-debug-ide' in VS Code

I am trying to use VS Code for debugging a Ruby on Rails application. I have installed both the Ruby and Rubocop extension into VS Code. Then I have installed ruby-debug-ide -v 0.6.0 and debase -v 0.2.1 both via sudo gem install and rvmsudo gem install. However, when trying to debug the application using Rails server, I get the following exception:
/usr/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs'
:
Could not find 'ruby-debug-ide' (>= 0.a) among 48 total gem(s)
(
Gem::LoadError
)
Checked in 'GEM_PATH=/home/myname/.rvm/gems/ruby-2.3.1:/home/myname/.rvm/gems/ruby-2.3.1#global', execute `gem env` for more information
from /usr/lib/ruby/2.3.0/rubygems/dependency.rb:328:in `to_spec'
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
from /usr/local/bin/rdebug-ide:22:in `<main>'
However, when I list all installed gems with rvm all do gem list, neither of the installed gems are there:
*** LOCAL GEMS ***
...
concurrent-ruby (1.0.2)
did_you_mean (1.0.0)
erubis (2.7.0)
...
rdoc (4.2.1)
rubygems-bundler (1.4.4)
rvm (1.11.3.9)
...
Does anybody know how to fix this?
In my case, the solution was quite simple. As a newbie in Ruby on Rails, I did not realize that instead of installing gems into Ruby root, I should specify them in my Gemfile. So, inside Gemfile I put only:
group :development do
gem 'ruby-debug-ide', '0.6.0'
gem 'debase', '0.2.1'
gem 'web-console', '~> 2.0'
gem 'spring'
end
and this solved the issue for me.
I also had this issue for a while, there doesn't seem to be a clear cut way of resolving this problem. All I had to do was run vs code through the terminal and I could debug my rails project, assuming you are using Linux. Just make sure you don't open vs code via a shortcut.

Gem dependencies in Rails Engines

I have followed the Getting Started with Engines in Rails documentation and I have set up an api engine in engines directory. According to the paragraph 6.6 Other Gem Dependencies one is supposed to define the gem dependencies in engines/my_api/my_api.gemspec file and that is pretty much what I did:
s.add_dependency "responders", "2.0"
After adding
`gem 'my_api', path: "engines/my_api"`
to the applications Gemfile and running bundler, everything looks as expected:
bundle install | grep responders
Installing responders 2.0.0
In the next step I set up a root path with a corresponding controller etc. and go to engines/my_api/app/controllers/my_api/application_controller.rb and add following content:
module MyApi
class ApplicationController < ActionController::Base
respond_to :json
end
end
I start the rails server, go the root url and guess what? I get following message:
The controller-level respond_to' feature has been extracted to the responders gem. Add it to your Gemfile to continue using this feature: gem 'responders', '~> 2.0' Consult the Rails upgrade guide for details.
As suggested in the error message, I've added the gem to the applications Gemfile, run bundle install and everything works as expected.
As far as I understood, engines are supposed to be self contained rails apps. From a self contained app I would at least expect to correctly resolve its dependencies. I assume that I am just doing something wrong and I hope someone will be able to help me to tackle down the problem, why do I have to explicitly specify the gem in the applications Gemfile?
EDIT:
Forgot to mention the versions:
$ gem list | grep rails
coffee-rails (4.1.0)
jquery-rails (4.0.3)
rails (4.2.1)
rails-deprecated_sanitizer (1.0.3)
rails-dom-testing (1.0.6)
rails-html-sanitizer (1.0.2)
sass-rails (5.0.3)
sprockets-rails (2.2.4)
As you observe, the gem is included in your bundle whether it is in your application's Gemfile or not. The difference is that when Bundler.require is called during application initialisation it only auto requires the gem's in your application's Gemfile - not indirect dependencies.
If your gem requires the responders gem gem to be loaded then it should require it explicitly - for example at the top of my_api.rb

Two separately namespaced Gemfiles in one Rails app?

I need to require these two gems in my Rails 3.2 app:
gem 'google-adwords-api'
gem 'netsuite'
However, they conflict on the versions of the savon gem. Bundler spits out this:
Bundler could not find compatible versions for gem "savon":
In Gemfile:
google-adwords-api (>= 0) ruby depends on
google-ads-common (~> 0.2.0) ruby depends on
savon (~> 0.9.1) ruby
netsuite (= 0.2.6) ruby depends on
savon (2.3.3)
I absolutely need both gems in my project, so this is what I've tried so far. I've moved the google-adwords-api gem into a custom Rails Engine I named "adx_interface" and mounted it within my Rails app. This engine has it's own Gemfile. If I put this line in my Rails app's Gemfile, then the Bundler error remains:
gem "adx_interface", "0.0.1", :path => "#{File.expand_path(__FILE__)}/../vendor/adx_interface"
Is there some way to namespace this engine so that it's dependencies aren't clashing with the apps dependencies? I've tried excluding the gem "adx_interface" line from the apps Gemfile, but that means I would have to start requiring gems manually instead of relying on Bundler. Is that a viable solution? If so, how do I go about including the google-adwords-api in such a way that it's namespaced properly and it's savon won't clash with netsuite's savon?
For what it's worth, I've personally contacted the author of the google-adwords-api gem. He said he likes the savon 0.9.1 gem and has no plans to ever update to a newer version.
What you are trying to do is exactly against the idea behind Bundler. Bundler exists to help you manage your dependencies and discover conflicts.
There is no clean way to bypass this restriction. The only solution I can think about, is to fork the google-adwords-api gem, bump the dependency and have your Gemfile to point to your custom fork.

rails sunspot nokogiri dependency

I am trying to follow the wiki instructions for getting sunspot on rails
https://github.com/outoftime/sunspot/wiki/Adding-Sunspot-search-to-Rails-in-5-minutes-or-less
Everything works fine until when I do:
$ rake sunspot:solr:start
rake aborted!
no such file to load -- nokogiri
However, it looks like I DO have nokogiri installed:
$ gem list
....
nokogiri (1.4.4)
....
Anyone have any thoughts? I'm on a mac if that makes a difference.
Are you including nokogiri in your Gemfile or environment.rb?
For rails 3 add this line to your Gemfile
gem 'nokogiri'
For rails 2 add config.gem to your environment.rb
config.gem "nokogiri"
It's also quite possible if you're using Rails 3 that your gem list command doesn't reflect the directory where bundler has installed the gems for your app.

Resources