Rails gem resque-loner NameError (uninitialized constant Resque::Plugins::UniqueJob) - ruby-on-rails

I have installed the gem, required from initializers and restarted server. But I get this error.
Gemfile
gem "resque-loner"
config/initializers/resque.rb
require 'resque-loner'
RefreshItemsJob
class RefreshItemsJob < ApplicationJob
include Resque::Plugins::UniqueJob

Related

Getting uninitialized constant error from unused gem

I was trying to use the Addressable gem in a specific action in Rails.
My usual practice is to include the gem in the Gemfile, and then require the module where needed.
Gemfile:
gem 'addressable'
some_controller.rb:
class SomeController < ApplicationController
def new
require "addressable/uri"
current_url = Addressable::URI.parse(request.original_url)
....
end
end
However, I was getting a 500 error on other actions/controllers that did not use the gem.
Error during failsafe response: uninitialized constant Addressable
Finally, I removed all the code calling addressable, but kept the entry in the gemfile, and the 500 error persists on all actions. Why would this be?
Not sure why you're getting that specific error, but with a gem like Addressable where you don't want an automatic require 'addressable' performed then in your Gemfile you should have:
gem 'addressable', :require => false

How do I create a command line rails generator gem?

I know how to create a rails generator gem which is called like:
rails g my_generator command
And I know how to create a thor gem which can be called like:
my_generator command
But I don't know how to create a rails generator that can be called using an executable. I have tried by creating a lib/my_generator/cli.rb file like:
require 'thor'
module Mang
class Cli < Thor
include ::Rails::Generators::Base
desc "install_gem", "install a gem"
def install_gem
gem 'thor', "0.18.1"
end
end
end
But I get the following error despite having added Rails as a dependency in my gemspec.
uninitialized constant Rails (NameError)
The fix was just a matter of including the rails/generators/actions module.
require 'thor'
require 'rails/generators'
require 'rails/generators/actions'
module Mang
class Cli < Thor
include Thor::Actions
include Rails::Generators::Actions
desc "install_gem", "install a gem"
def install_gem
gem 'thor', "0.18.1"
end
end
end

Trouble running httparty in rails 4.0 with ruby 2.0

To include httparty in my rails 4.0.0 app, in my gemfile I wrote:
gem 'httparty'
and then ran bundle install
Next in my application.rb file, I inserted this:
module myApp
class Application < Rails::Application
### ---
config.gem "httparty"
### ---
end
Now when I load rails c and do a require "httparty", I get false
What am I doing wrong? How do I load httparty in my rails app?
It's already loaded by Rails. You also don't need the config.gem in application.rb
Try using HTTParty from the console. It should just work.

Rails 3: Routing Error - uninitialized constant MyController::Google

I'm using the google-api-client gem (gem google-api-client, '0.4.1' in my Gemfile). The following code caused the error uninitialized constant MyController::Google:
class MyController < ApplicationController
def index
#client = Google::APIClient.new
end
end
Specifying ::Google::APIClient didn't help, the error then said uninitialized constant Google.
Simply adding a require 'google/api_client' at the top of the file made this go away, so it seems there's something wrong in how auto-loading is being done. Not sure what's going on here exactly, specifying the gem in my Gemfile should have automatically required the gem, right? I have restarted the rails server btw.
Try adding a :require => 'google/api_client' where you specify the google api client gem in the Gemfile
gem 'google-api-client', :require => 'google/api_client'
This tells bundler that the correct way to require the gem 'google-api-client' is to require 'google/api_client'

require other modules in the controller

gem install rubyoverflow
irb
> require 'rubyoverflow'
=> true
But:
require 'rubyoverflow'
include Rubyoverflow
class QuestionsController < ApplicationController
def question_by_tag
ruby_q = Questions.retrieve_by_tag('ruby')
Get error:
LoadError in
QuestionsController#question_by_tag no
such file to load -- rubyoverflow
Rails.root:
D:/artefacts/dev/projects/stack
app/controllers/questions_controller.rb:1:in
`'
This error occurred while loading the
following files: rubyoverflow
Is there any special rules to import moduled in the controller?
why do you use both require and include? include Rubyoverflow will be enough
UPD
For gem you should add it into your Gemfile (Rails 3.x) or config/environment.rb (Rails 2.x)
# Gemfile
gem "rubyoverflow"
# environment.rb
config.gem "rubyoverflow"
Then run bundle for Rails 3.x and rake gems:install for Rails 2.x

Resources