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

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 :)

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'

getting godmin-tags gem errors on starting rails

I get the following error when I try to start up rails or if I run rails console.
.rvm/gems/ruby-2.3.3#adventure_map/gems/godmin-tags-1.0.1/lib/godmin/tags/helper.rb:11:in '<module:Godmin>': uninitialized constant Godmin::FormBuilders (NameError)
I have included the gem godmin-tags , using haml for templating and running rails-5.0.1
No issue has been raised on its github page and I can seem to find a solution to this
Part of my Gemfile is:
gem 'godmin-tags'
gem 'godmin' # administrative interface https://github.com/varvet/godmin
gem 'devise_token_auth'
gem 'omniauth'
Make sure you include godmin-tags after godmin ;-)

Undefined method 'register_engine' while trying to install Ember to Rails

I started learning Ember.js using Rails as back-end, and created a test project. So, first I removed turbolinks from app and added the following gems to Gemfile:
gem 'ember-rails'
gem 'ember-source', '~> 1.8.1'
gem 'emblem-rails'
and bundled them. Next, I ran
$ rails g ember:bootstrap -n App --javascript-engine js
and it has returned me the following error:
/home/alex/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/emblem-rails-0.2.2/lib/emblem/rails/engine.rb:7:in
`block in <class:Engine>':
undefined method `register_engine' for nil:NilClass (NoMethodError)
Is the problem that something can be deprecated? I'm following the tutorial written in 2014.
The trouble was caused by emblem-rails gem - I commented it out, and everything worked

uninitialized constant Request (NameError)

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.

Rails 3 gem installed with bundler, still get NoMethodError

I'm trying to install the calendar_helper gem. I included the gem in my Gemfile:
gem 'calendar_helper'
I ran bundle install and loaded fine.
Using calendar_helper (0.2.4)
0.2.4 is the newest version in GitHub, so that looks good. I'm running on Pow so I don't need to restart the server (though I tried that anyway). Adding a call to the method calendar throws an error:
undefined method `calendar'
I feel like something could be wrong with my Rails installation or something. Any ideas?
It doesn't look like version 0.2.4 is up-to-date with what's on github; it's missing the subclass of Rails::Engine necessary to load the helper. The key line on the edge source is here: https://github.com/topfunky/calendar_helper/blob/master/lib/calendar_helper.rb#L231.
You may be able to fix this by installing the gem from edge:
gem 'calendar_helper', :git => 'git://github.com/topfunky/calendar_helper.git'
Edited:
If that still isn't working, you can also try this in your ApplicationHelper:
require 'calendar_helper'
module ApplicationHelper
include CalendarHelper
end

Resources