require 'watir-webdriver' error - ruby-on-rails

I am trying to use Watir with Rails, and installed it, and when I use it from irb, it works fine. But when I try to include it in rails application, as
require 'rubygems'
require 'watir-webdriver'
I get the following error:
LoadError (no such file to load -- watir-webdriver)
Some people had experienced the same problem, which was solved by using require 'rubygems', butin my case, the problem still persists. Any idea?

Did you add gem 'watir-webdriver' to your Gemfile in Rails root folder?

Related

require bindata in ruby on rails application

I have a set of files that are in the lib directory of a Ruby on Rails application.
I have a model that needs to use these files. In my model I have the following:
require_relative '../../some_path_to_file_without_extention'
(Side note; I would love to know a way to require all the files, instead of require_relative for each file).
The file that I require_relative has the following require in it.
require "bindata"
When I try to access functions from the require_relative file I get the following error:
LoadError: cannot load such file -- bindata
This is happening for other gems that are being required in the set of files as well. I just chose bindata as an example.
I have bindata in my Gemfile. When I run bundle show bindata it shows me the path to bindata.
I even put require 'bindata' in my model, but it gave me the same load error.
How do I stop the LoadError?
Any help would greatly be appreciated.
Update 1
When I run bundle show . I get the following:
Gems included by the bundle:
...
* bcrypt (3.1.11)
* bindata (2.3.4)
...
Then in the console, requiring bcrypt works but bindata does not.
irb(main):002:0> require 'bcrypt'
=> true
But bindata does not.
irb(main):003:0> require 'bindata'
LoadError: cannot load such file -- bindata
Update 2
Ok so I know is has to be something with how I am loading my rails environment.
bundle exec irb
irb(main):001:0> require 'bindata'
=> true
Update 3
So I went back a few git commits and keep trying to add the gems and see if they would load in my rails console. I went back far enough were it did. Did not know what was different. However, I also noticed when my spring server was restarted then my gems would load in my rails console.
To require all the files in the lib folder, add config.autoload_paths << Rails.root.join('lib') to your application.rb, this answer can help you: https://stackoverflow.com/a/19650564/3739191
Now,
require 'bindata'
should work :)

Contact gem in ruby on rails

I followed this blog. I found one error: I mentioned in environment.rb require ‘contacts’.
When I use this require ‘contacts’ the server never started. When I replace this require ‘contacts’ the server starting but some syntax errors came in URL. How can I import my contacts?
That blog entry predates Rails 3, and thus does not refer to the fact that you must add the following to your Gemfile:
gem 'contacts'
and then run bundle install. As a result of this you do not need to put require 'contacts' anywhere, as Bundler will require it for you.

Rails gem - geoipcity is not being included in the application

I installed the geoip_city gem, and i tested the gem in irb... Now when I am using the gem in the application I get an error
uninitialized constant ApplicationController::GeoIPCity
I guessed it is because I did not add the line
require geoip_city
So I tried adding the line to the function I used the code in, but then I got the error
No such file -- geoip_city
Please help.
Have your require rubygems before ?
require 'rubygems'
require 'geoip_city'

uninitialized constant Twitter::OAuth - Overlooking a require somewhere?

I'm looking to use the latest Twitter gem for a Rails app I'm working on.
However, executing the following line:
oauth = Twitter::OAuth.new(ServiceAPIKeys.twitter['api_key'], ServiceAPIKeys.twitter['secret_key'])
Triggers the following exception:
uninitialized constant Twitter::OAuth
I do have the gem configured in my environment.rb using 'config.gem 'twitter'' and I have the gem unpacked into my vendor/gems directory. I've also tried tossing a 'require 'twitter'' inside the controller where I'm calling it.
Am I missing something obvious or is this an issue with the current gem?
What worked for me (Twitter4r is not installed on my system) is inserting "gem 'twitter'" like in:
require 'rubygems'
gem 'twitter' <<--- INSERT THIS
require 'twitter'
Problem found. There was another included gem, 'Twitter4r' that was using the Twitter namespace and it was taking precedence over the Twitter gem.

How do I get an installed ruby gem included in Rails?

I am attempting to get a gem I installed working in a Rails application. I can require the gem just fine in a Ruby program that I run from the command line using:
require 'nokogiri'
But when I attempt to do the same in one of my Rails controllers it errors saying "no such file to load -- nokogiri".
I tried using the full path to the lib/nokogiri.rb file, but that fails because it cannot find "nokogiri/native".
Better, place the following in your environment.rb file:
Rails::Initializer.run do |config|
...
config.gem :nokogiri
...
end
This will tell Rails that you depend on that particular gem. It also allows you to specify particular versions, and it will automatically keep all your gems synched, or unpack them into vendor/gems if you so wish.
I had a similar error but simply forgot to put the following in my environment.rb file: (note the quoted "nokogiri")
Rails::Initializer.run do |config|
...
config.gem "nokogiri"
...
end
Ok I figured it out. This is going to sound pretty stupid...but oh well...
It turns out I had two installations of ruby on my machine. I use InstantRails to serve my test applications and it comes prepackaged with an installation of ruby. I had another installation however outside of this and it was here that nokogiri had been installed, not in the installation in InstantRails.
In any case they were looking in different spots for the gems.
Try the following
require 'rubygems'
gem 'nokogiri'
If you are on some form of *nix then did you get any errors when you installed the gem, particularly errors stating that the gem was not on the path. This may happen if you have installed the gem as yourself rather than as root and you do not have your personal gem library in your gem path.
If you always install your gems using
sudo gem install some_gem_name
then you should not get that problem.

Resources