uninitialized constant Request (NameError) - ruby-on-rails

I get this error: /LiveToChallenge/config/initializers/gibbon.rb:1:in '<top (required)>': uninitialized constant Gibbon::Request (NameError) when I try to start the server rails server.
app/config/initializers/gibbon.rb
require 'gibbon'
Gibbon::Request.api_key = "24e4a2233cd34debb76ed083dc3f8b5379-us8"
Gibbon::Request.timeout = 15
I followed gibbon gem instructions, which seemed simple enough. Maybe I'm missing something besides just gem install gibbon and adding api_key to initializer?
The gem is installed as gibbon (2.2.2, 2.2.1, 1.2.1)
And as added measure I put gem gibbon in the gemfile and ran bundle install
This problem is part of a larger problem I've been working on solving.

I experienced same issue with gibbon 2.0 version as it has updated some methods for initializations then i tried a previous version & it worked but first You should try it this way :
gibbon = Gibbon::Request.new(api_key: "MailChimp_API_Key")
gibbon.timeout = 10
If no luck with this in app/config/initializers/gibbon.rb then you can try to do this direct in the controller just before using gibbon to retrieve or add list stuff for testing.

You should add the gem to the rails Gemfile. Then rails will take care of the require 'gibbon' for you.
Edit: gem install gibbon will just install the gem on your system. Rails won't know that it is needed unless you add it to the Gemfile.

Related

What's the replacement for acts_as_commentable in Rails 6, Ruby 3.0.2?

I upgraded our app to Rails 6.1.4.4 and Ruby 3.0.2. I have this old gem
gem 'acts_as_commentable'
Locked at version 4.0.2. The gem does not appear to be supported anymore, which is a shame because when I start up my app or console, I now get this error
$ rails c
Your Gemfile lists the gem rspec-rails (>= 0) more than once.
You should probably keep only one of them.
Remove any duplicate entries and specify the gem only once.
While it's not a problem now, it could cause errors if you change the version of one of them later.
/Users/myuser/.rvm/gems/ruby-3.0.2/gems/hash_dot-2.5.0/lib/hash.rb:19:in `method_missing': undefined method `arity' for {:as=>:commentable, :dependent=>:destroy}:Hash (NoMethodError)
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:53:in `build_scope'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:47:in `create_reflection'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:32:in `build'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations.rb:1458:in `has_many'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/acts_as_commentable-4.0.2/lib/commentable_methods.rb:58:in `acts_as_commentable'
…
Is there any simple replacement for this gem or way to monkey-patch this error so I can start up the app?
Looking over the forks, I found this one that appears to work for me using Rails 6.0.6 and Ruby 3.0.5.
https://github.com/alazycoder101/acts_as_commentable.git
I have not tested it extensively yet, but at least the basic functionality seems to be working for me. Hope this helps.
For clarity, to use that fork you would use the following line in your Gemfile:
gem 'acts_as_commentable', git: 'https://github.com/alazycoder101/acts_as_commentable.git'

Uninitialized constant while using gem in rails

I am trying to run the following code to initialize the official EventbriteClient
eb_client = EventbriteClient.new(eb_auth_tokens)
however, I faced the uninitialized constant WelcomeController::EventbriteClient
I double checked and confirmed gem is installed.
Seems like you forget to add this gem to your Gemfile:
gem 'EventbriteClient'

Rails gcal4ruby gem uninitialized

I'm trying to create a Ruby on Rails web app that will sync with google calendar. I tried to use omniauth but it didn't work for me.
I found a rails gem that should do the job for me: gcal4ruby
But for now it isn't working.
I use the code:
#serv = Service.new
#serv.authenticate 'account#gmail.com', 'pass'
and got an error:
uninitialized constant UsersController::Service
In my gemfile using:
gem 'gcal4ruby', '0.5.5'
Gem was installed successfully after bundle install.
By trying to use similar gems I got the same error so I suppose that issue is something else.
I tried to use require "gcal4ruby" in my code and got error:
cannot load such file -- gcal4ruby
I'm using ruby 1.9.3 and rails 4.0.2.
Thanks for help.
Try:
require 'gcal4ruby'
include GCal4Ruby
Which mixes-in the Service class.
Note, that GCal4Ruby uses version 2 of the google calendar api which is deprecated and will not work after November-17th 2014.
Here is a great tutorial on getting a rails app working using omniauth.

Undefined constant "RestClient" after rest-client gem has been installed

Just added gem "rest-client", "~> 1.6.7" to my gem file and ran bundle install.
Trying to make the app send a get request to a local jetty
#server = "http://127.0.0.1:3333"
RestClient.get #server+'/command/core/get-version'
results in
uninitialized constant XController::RestClient
UPDATE:
Question solved, I forgot to restart the webserver.
The problem is that it requires to restart the server for freshly installed gems to come in effect.
Outside rails, I ran into the same problem. Solution:
require 'rest-client'
It happened to me few times i named the gem restclient instead of rest-client :) Both gems exist, but the one with dash is the correct one.

undefined method 'configure' inside the initializer? added a new ruby gem

I installed the gem Bitly into my rails app
I did it by running gem install bitly
then I manually added gem 'bitly' into my gemfile
I created this inside `config\initializers\bitly.rb
Bitly.configure do |config|
config.api_version = 3
config.login = "myusername"
config.api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
end
I'm trying to get my rails server running but I get this error I've never seen before
Exiting
C:/app/config/initializers/bitly.rb:1:in `<top (
required)>': undefined method `configure' for Bitly:Module (NoMethodError)
How can I resolve this issue and make this gem work?
I am trying to use the gem inside one of my models
bitly.shorten("http://mydomain.com/article/#{id}")
Bitly is currently available in version 0.8.1 on rubygems. This version does not support Bitly.configure. I recomend you use the gem from github, until someone releases a newer version on rubygems.
The bitly line in your Gemfile should look like this:
gem "bitly", :git => 'https://github.com/philnash/bitly/'
Then do a bundle install and bitly should work the way you expect.
Edit: There is even a github issue for that error :)

Resources