Error initializing ShortCode Gem - ruby-on-rails

I have a problem initializing the Rails Gem shortcode.
I have this code in initializers / shortcode.rb
Shortcode.setup do |config|
config.template_parser = :haml
config.template_path = "support/templates/chart"
config.block_tags = [:chart]
end
When I start the server rails (rails s) gives the following error.
/home/usuario/proyectos/rails/crowdfunding/config/initializers/shortcode.rb:3:in `<top (required)>': uninitialized constant Shortcode (NameError)
from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/engine.rb:652:in `block in load_config_initializer'
from /usr/local/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/notifications.rb:166:in `instrument'
from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/engine.rb:651:in `load_config_initializer'
Note: I already did install bundle and bundle update sass-rails

Shortcode is not a Rails gem but the ruby gem [thus Rails come without this gem as its dependency]. Add gem 'shortcode' in your Gemfile, bundle the project and restart the application.

Related

Active admin install error

I have an error, when try to run command:
rails g active_admin:install
The error is:
user#user1:~/projectX$ rails g active_admin:install
invoke devise
/home/user/.rvm/gems/ruby-2.2.0/bundler/gems/activeadmin-6bde1f57ec5f/lib/generators/active_admin/devise/devise_generator.rb:21:in rescue in install_devise': uninitialized constant ActiveAdmin::Generators::DeviseGenerator::DependencyError (NameError)
from /home/user/.rvm/gems/ruby-2.2.0/bundler/gems/activeadmin-6bde1f57ec5f/lib/generators/active_admin/devise/devise_generator.rb:19:ininstall_devise'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/command.rb:27:in run'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:ininvoke_command'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in block in invoke_all'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:ineach'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in map'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:ininvoke_all'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/group.rb:232:in dispatch'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:115:ininvoke'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/group.rb:277:in block in _invoke_for_class_method'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/shell.rb:68:inwith_padding'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/group.rb:266:in _invoke_for_class_method'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/group.rb:133:in_invoke_from_option_users'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/command.rb:27:in run'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:ininvoke_command'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in block in invoke_all'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:ineach'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in map'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:ininvoke_all'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/group.rb:232:in dispatch'
from /home/user/.rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/base.rb:440:instart'
from /home/user/.rvm/gems/ruby-2.2.0/gems/railties-4.2.0/lib/rails/generators.rb:157:in invoke'
from /home/user/.rvm/gems/ruby-2.2.0/gems/railties-4.2.0/lib/rails/commands/generate.rb:13:in'
from /home/user/.rvm/gems/ruby-2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:123:in require_command!'
from /home/user/.rvm/gems/ruby-2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:130:ingenerate_or_destroy'
from /home/user/.rvm/gems/ruby-2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:50:in generate'
from /home/user/.rvm/gems/ruby-2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:inrun_command!'
from /home/user/.rvm/gems/ruby-2.2.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in <top (required)>'
from /home/user/projectX/bin/rails:8:in'
from /home/user/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require'
from /home/user/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from -e:1:in `'
Active admin and devise gems are installed. The only problem is when I generate active admin. I use Rails-4.1.8 and ruby-2.1.4.
Thanks for help and good day.
You need to add the gem 'devise' to your Gemfile or directly using the cli
bundle add devise
or you need to run the install with the the --skip-users flag.
rails g active_admin:install --skip-users
activeadmin gem (I mean latest version of gem on rubygems.org) still is not compatible with Rails 4.x.
Try to use use latest version of activeadmin from repository:
gem 'activeadmin', github: 'activeadmin/activeadmin', branch: :master
Works for me.
gem 'devise', '~> 3.2'

Sidekiq Install - uninitialized constant ActiveRecord::Base (NameError)

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.

uninitialized constant Test::Unit::UI::XML (NameError) in Rails (or Ruby)

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/

"require 'capybara/rails'" gives "uninitialized constant Rack::Builder"

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.

issue installing active admin - rails 3.0.3 - uninitialized constant Formtastic::SemanticFormHelper

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

Resources