I am trying to integrate Sidekiq with my Rails Mongoid app. I have been following the steps as outlined Here
I also have redis & mongodb running locally. However after I run bundle then when I try to start my server I get this error....
c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sidekiq-2.17.7/lib/sidekiq/rails.rb:4:in `hook_rails!': uninitialized constant ActiveRecord::Base (NameError)
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sidekiq-2.17.7/lib/sidekiq/rails.rb:16:in `block in <class:Rails>'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
from C:/Users/example/Documents/Workspace/app/config/environment.rb:5:in `<top (required)>'
My environment.rb file is as follows...
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
App::Application.initialize!
I previously had resque with redis working with mongoid in this app, so its a sidekiq issue. I don't have a database.yml file since I am using mongoid. I also added the steps for kiqstand but I am getting the same error. Unsure how to resolve?
Edit: I'm 90% sure its because Sidekiq is looking for ActiveRecord, however I removed ActiveRecord cause I'm using Mongo instead. My application.rb has...
# remove activerecord and run off of mongo only
#require 'rails/all'
#http://stackoverflow.com/a/9327651/1026266
%w(
action_controller
action_mailer
active_resource
rails/test_unit
sprockets
).each do |framework|
begin
require "#{framework}/railtie"
rescue LoadError
end
end
Now I just need to figure out how to tell sidekiq to not look for it?
Lack of ActiveRecord was the issue, looks like there was a pull request - https://github.com/mperham/sidekiq/pull/1090
But that was rejected, so I just had to add ActiveRecord to my app and add a dummy database.yml file.
Related
For some reason, on heroku it will not allow me to import models (this is for the Bonsai ElasticSearch add-on). It's just showing connection refused. I'm not sure how to resolve this. I've searched the internet and I can't find anything that will even hint me in the right direction to solve this. I checked to make sure the server was up and manually created the index with curl. Do the initializers get launched when running a rake task?
I set the elasticsearch url in the config/initializers/bonsai.rb file:
config/initializers/bonsai.rb
if Rails.env == 'production'
ENV['ELASTICSEARCH_URL'] = ENV['BONSAI_URL']
end
Gemfile snippet
# Used for elastic search
gem 'elasticsearch-model', github: 'elasticsearch/elasticsearch-rails'
gem 'elasticsearch-rails', github: 'elasticsearch/elasticsearch-rails'
gem 'multi_json'
gem 'json'
Error
heroku run rake environment elasticsearch:import:all DIR=app/models
Running `rake environment elasticsearch:import:all DIR=app/models` attached to terminal... up, run.5751
[IMPORT] Loading models from: app/models
[IMPORT] Processing model: Firm...
rake aborted!
Connection refused - connect(2)
/app/vendor/bundle/ruby/2.0.0/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:80:in `perform_request'
/app/vendor/bundle/ruby/2.0.0/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:39:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:139:in `build_response'
/app/vendor/bundle/ruby/2.0.0/gems/faraday-0.9.0/lib/faraday/connection.rb:377:in `run_request'
/app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.1/lib/elasticsearch/transport/transport/http/faraday.rb:21:in `block in perform_request'
/app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.1/lib/elasticsearch/transport/transport/base.rb:187:in `call'
/app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.1/lib/elasticsearch/transport/transport/base.rb:187:in `perform_request'
/app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.1/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
/app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-transport-1.0.1/lib/elasticsearch/transport/client.rb:102:in `perform_request'
/app/vendor/bundle/ruby/2.0.0/gems/elasticsearch-api-1.0.1/lib/elasticsearch/api/actions/bulk.rb:81:in `bulk'
/app/vendor/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-26a3ba246968/elasticsearch-model/lib/elasticsearch/model/importing.rb:78:in `block in import'
/app/vendor/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-26a3ba246968/elasticsearch-model/lib/elasticsearch/model/adapters/active_record.rb:88:in `block in __find_in_batches'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.0/lib/active_record/relation/batches.rb:125:in `find_in_batches'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.0/lib/active_record/querying.rb:9:in `find_in_batches'
/app/vendor/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-26a3ba246968/elasticsearch-model/lib/elasticsearch/model/proxy.rb:80:in `method_missing'
/app/vendor/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-26a3ba246968/elasticsearch-model/lib/elasticsearch/model/adapters/active_record.rb:86:in `__find_in_batches'
/app/vendor/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-26a3ba246968/elasticsearch-model/lib/elasticsearch/model/importing.rb:77:in `import'
/app/vendor/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-26a3ba246968/elasticsearch-model/lib/elasticsearch/model.rb:113:in `import'
/app/vendor/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-26a3ba246968/elasticsearch-rails/lib/elasticsearch/rails/tasks/import.rb:59:in `block (3 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-26a3ba246968/elasticsearch-rails/lib/elasticsearch/rails/tasks/import.rb:99:in `block (4 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-26a3ba246968/elasticsearch-rails/lib/elasticsearch/rails/tasks/import.rb:82:in `each'
/app/vendor/bundle/ruby/2.0.0/bundler/gems/elasticsearch-rails-26a3ba246968/elasticsearch-rails/lib/elasticsearch/rails/tasks/import.rb:82:in `block (3 levels) in <top (required)>'
Tasks: TOP => elasticsearch:import:model
(See full trace by running task with --trace)
by the way can someone create an 'elasticsearch-rails' tag since its the upcoming replacement for Tire
Elasticsearch Rails does not use the same mechanism as Tire to set its URL in production on Heroku. To have this work correctly with Bonsai search, you have to have a different url specification. Fortunately a guy has made a gem (https://rubygems.org/gems/bonsai-elasticsearch-rails) to eliminate the needless, mandatory creation of a initializer by everyone.
Simply add this gem to your gem file under your production group. The version may be subject to change since it's so new:
gem 'bonsai-elasticsearch-rails', '~> 0.0.4'
If you're more curious about what this gem actually does, the entire source is below:
require "bonsai/elasticsearch/rails/version"
puts "Starting up a new ElasticSearch client with #{ENV['BONSAI_URL']}"
Elasticsearch::Model.client = Elasticsearch::Client.new url: ENV['BONSAI_URL']
I know, simple right...
I updated a Rails 2.3 app to 3.2 and it seemed to be a pretty simple process but when setting up the Figaro gem I came across this error:
C:\Sites\JustManage>rails generate figaro:install
C:/Sites/JustManage/config/environment.rb:5:in `<top (required)>': uninitialized
constant Projectmanagement (NameError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
/lib/rails/application.rb:103:in `require_environment!'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
/lib/rails/commands.rb:25:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Here is what my environment.rb looks like:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Projectmanagement::Application.initialize!
Here is my application.rb file:
require File.expand_path('../application', __FILE__)
require 'rails/all'
if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
end
module Railsapp
class Application < Rails::Application
config.encoding = "utf-8"
config.filter_parameters += [
:password,
:password_clear,
:password_verify
]
config.assets.enabled = true
config.assets.version = '1.0'
end
end
I've never run into this error before and don't know why it's happening.
It seems like the name of your application is not the same in the different places it needs to appear in. Check the following files and see if they contain either Projectmanagement::Application or Railsapp::Application:
config/application.rb (Actually initializes the constant)
config/environment.rb
config/environments/development.rb
config/environments/production.rb
config/environments/test.rb
config/initializers/secret_token.rb
config/initializers/session_store.rb
config/mongoid.yml (if using Mongoid)
config/routes.rb
config.ru
Rakefile
app/views/layouts/application.html.erb, in title tag
Then pick a name (either Projectmanagement or Railsapp) and change all the names in the above files so they match. That should resolve the uninitialized constant error you are having.
I can't be certain that they are not errors from copy/pasting, but your application.rb appears to be incorrect. Issues I see:
L1: You are requiring application.rb a second time where you mean to be requiring boot.rb.
L12: The name of this module (i.e. the name of your app) is not consistent here with what is in your environment.rb file (Railsapp vs. Projectmanagement).
The second issue is actually causing the error you are seeing - you have not defined the Projectmanagement constant before calling a method on it.
I'm trying to create an xml runner to make a result report of Rails unit testing. Here is a code I have:
require 'test/unit'
require 'test/unit/ui/console/testrunner'
class FastFailRunner < Test::Unit::UI::Console::TestRunner
def add_fault(fault)
#faults << fault
nl
output("%3d) %s" % [#faults.length, fault.long_display])
output("--")
#already_outputted = true
end
def finished(elapsed_time)
nl
output("Finished in #{elapsed_time} seconds.")
nl
output(#result)
end
end
Test::Unit::AutoRunner::RUNNERS[:fastfail] = proc do |r|
FastFailRunner
end
When I run it as TESTOPTS="/home/alex/RubymineProjects/app2/test/unit/runner.rb --runner=xml" rake test
... I get an error (pretty weird error)
/home/alex/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/ext/module.rb:36:in `const_missing': uninitialized constant Test::Unit::UI::XML (NameError)
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/runner/xml.rb:5:in `block in <module:Unit>'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:389:in `[]'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:389:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:58:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit.rb:501:in `block in <top (required)>'
gem install minitest
/home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/runner/xml.rb:5:in `block in <module:Unit>': uninitialized constant Test::Unit::UI::XML (NameError)
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:389:in `[]'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:389:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit/autorunner.rb:58:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/test-unit-2.5.2/lib/test/unit.rb:501:in `block in <top (required)>'
Errors running test:units! #<RuntimeError: Command failed with status (1): [/home/alex/.rvm/rubies/ruby-1.9.3-p194/bin...]>
Errors running test:functionals! #<RuntimeError: Command failed with status (1): [/home/alex/.rvm/rubies/ruby-1.9.3-p194/bin...]>
I tried to require test/unit/ui/xml/testrunner.rb but no luck.
Any thoughts?
If you are in Ruby 1.8.7 you can say:
require 'test/unit/ui/console/testrunner'
p Test::Unit::UI::Console::TestRunner # => no problem
(There is no such file as test/unit/ui/xml/testrunner.rb so I'm not sure what you were up to there.)
Look in the docs in test/unit.rb, there's actually sample code showing you how to do this require: http://www.ruby-doc.org/stdlib-1.8.7/libdoc/test/unit/rdoc/Test/Unit.html.
However, the problem is that you are in Ruby 1.9.3. There is no /test/unit in Ruby 1.9.3! Well, there is, but it's just a compatibility layer for basic tests; there is certainly no test/unit/ui/console/testrunner, and no module/class Test::Unit::UI::Console::TestRunner.
Instead, there's minitest. You can read the docs on minitest to see how to make a test runner. http://docs.seattlerb.org/minitest/
One thing to consider is that Test::Unit was included in the default Ruby 1.8.7 installation. If you want to use it in with a later version of Ruby then go ahead and install it as a gem.
sudo gem install test-unit
http://test-unit.rubyforge.org/
I've been using cucumber in my app, which is a rails 2.2.2 app running in ruby 1.8.6 (upgrading isn't an option right now). Cucumber's been fine, now i'm trying to use Capybara. I've installed the capybara (1.1.1) gem and put the line require 'capybara/rails' in my features/support/env.rb file.
Now, when i run cucumber, i get this error:
Using the default profile...
uninitialized constant Rack::Builder (NameError)
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:445:in `load_missing_constant'
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:77:in `const_missing'
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/gems/capybara-1.1.1/lib/capybara/rails.rb:4
/home/max/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
/home/max/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:155:in `require'
/home/max/work/charanga/elearn_container/elearn/features/support/env.rb:10
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/rb_support/rb_language.rb:143:in `load'
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/rb_support/rb_language.rb:143:in `load_code_file'
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/runtime/support_code.rb:171:in `load_file'
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/runtime/support_code.rb:83:in `load_files!'
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/runtime/support_code.rb:82:in `each'
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/runtime/support_code.rb:82:in `load_files!'
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/runtime.rb:137:in `load_step_definitions'
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/runtime.rb:39:in `run!'
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/cli/main.rb:43:in `execute!'
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/gems/cucumber-1.1.1/bin/../lib/cucumber/cli/main.rb:20:in `execute'
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/gems/cucumber-1.1.1/bin/cucumber:14
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/bin/cucumber:19:in `load'
/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/bin/cucumber:19
Here's the erroring file:
#/home/max/.rvm/gems/ruby-1.8.6-p420#elearning-resource/gems/capybara-1.1.1/lib/capybara/rails.rb
require 'capybara'
require 'capybara/dsl'
Capybara.app = Rack::Builder.new do
map "/" do
if Rails.version.to_f >= 3.0
run Rails.application
else # Rails 2
use Rails::Rack::Static
run ActionController::Dispatcher.new
end
end
end.to_app
Capybara.asset_root = Rails.root.join('public')
Capybara.save_and_open_page_path = Rails.root.join('tmp/capybara')
So, line 4 is creating the error with the Rack::Builder.new line. But, why? Any ideas? I have the Rack gem installed already.
thanks, max
Try adding require 'rack/builder' before the require 'capybara/rails'in features/support/env.rb. Rails versions lower than 2.3 don't use Rack internally and thus Rack::Builder will not be loaded like capybara seems to be assuming.
Did you use the cucumber-rails gem?
https://github.com/jnicklas/capybara says, either use the gem or, if your're not using rails, put both these lines in:
require 'capybara/cucumber'
Capybara.app = MyRackApp
try this out
gem install rack
require 'rack' # in features/support/env.rb before every require
Rack::Builder is defined in rack library.
I'm trying to add activeadmin to my rails 3.0.3 app.
I'm following the instructions here
When I run - rake db:migrate I get the following error -
rake aborted!
uninitialized constant Formtastic::SemanticFormHelper
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/namespace.rb:167:in `eval'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/resource_controller.rb:1:in `<top (required)>'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/dashboards/dashboard_controller.rb:3:in `<module:Dashboards>'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/dashboards/dashboard_controller.rb:2:in `<module:ActiveAdmin>'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/dashboards/dashboard_controller.rb:1:in `<top (required)>'
(eval):1:in `generate_dashboard_controller'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/namespace.rb:167:in `eval'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/namespace.rb:167:in `generate_dashboard_controller'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin/namespace.rb:38:in `initialize'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin.rb:147:in `new'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin.rb:147:in `find_or_create_namespace'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin.rb:282:in `load_default_namespace'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin.rb:188:in `load!'
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.2.2/lib/active_admin.rb:212:in `routes'
You seem to be missing the formtastic gem. In the current version of active-admin (0.3.2) it is correctly specified as a dependency.
So I hope updating the activeadmin gem (bundle update activeadmin) will fix it.
If that does not fix it, I would add formtastic explicitly to the Gemfile.
Hope this helps.
In rails 3 the Formtastic::SemanticFormHelper became => Formtastic::Helpers::FormHelper
Don't forget to load your lib. By default rails don't load them so you can just uncomment config.autoload_paths += %W(#{config.root}/lib) in your application.rb