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'
Related
I'm trying to use the barby gem that I installed, but when I do it gives me this error.
LoadError cannot load such file -- barby
Here's the require methods in my controller.
require 'barby'
require 'barby/barcode/ean_13'
require 'barby/outputter/ascii_outputter'
require 'barby/outputter/html_outputter'
class PalletsController < ApplicationController
-snip-
end
Here's the gem in my gemfile.
gem 'barby'
Any help would be greatly appreciated.
You only add require when you are dealing with a ruby project. In your case(ruby-on-rails), you can remove those lines.
Also, keep in mind that you should add your gems into your Gemfile
bundle install? It sounds like you do not have the gem installed when ruby tries to load it, it can not find it. Gem list will list out the installed gems on the system, or bundle exec gem list.
gem list
I'm trying to use the HTTParty gem as a part of the gem that I am creating; however I keep getting an uninitialized constant NameError or 'require': cannot load such file -- httparty LoadError. My class starts like this:
module Reporting
class GitlabIssue
include HTTParty
...
Leaving this at it is, I receive the following error:
uninitialized constant Reporting::GitlabIssue::HTTParty (NameError)
Various searches turned up the solution for this is to require 'httparty' before the class block is opened. So I put the following at the top of my file:
require "httparty"
With that in place, I receive this error:
'require': cannot load such file -- httparty (LoadError)
My gemspec has the seemingly correct command to use the gem:
spec.add_dependency "httparty"
and when I do a bundle update/install, it lists the httparty gem as being installed and at version 0.13.3
When I load up an irb session, I can successfully require 'httparty' and it returns true without any errors. Any ideas what could be going on here?
Some system info: I'm running ruby 2.1.0p0 [x86_64-linux] and Rails 4.1.1
I think this has to do with the order that your files (and HTTParty) are loaded in your gem. If you have the standard directory layout for your gem try this:
In your_app.gemspec ->
spec.add_dependency 'httparty'
At the top of your_app/lib/your_app.rb ->
require 'httparty'
I just runned in the exact same issue here.
Turns out I included HTTPParty instead of HTTParty
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?
I'm having an issue with using RedCloth in my local application. I keep getting the following error:
uninitialized constant ActionView::CompiledTemplates::RedCloth
This happens because I have the following code:
<%= RedCloth.new("Some text").to_html %>
What I tried to do is put this in the environment.rb file:
require "RedCloth"
However, when I do this, I get a huge error with my Phusion Passenger + Nginx configuration, which I've detailed in the following forum: http://railsforum.com/viewtopic.php?id=42560
Any help would be great. Thanks!
Make sure your Gemfile has a gem 'RedCloth' in it. Regardless of which gems are actually installed in your system, Rails will only use the gems listed in your Gemfile. You do not need the require "RedCloth" statement either.
I had exactly the same error and gem 'RedCloth' line was present in Gemfile. What helped was adding require statement in the beginning of controller file
require 'redcloth'
class StaticController < ApplicationController
...
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.