I recently started getting problems in generating controllers,models and starting rails server in new projects. I am able to do all these things in old projects.
What can be done to resolve this error?
OS: Ubuntu 15.04 ,Ruby:2.1 ,Rails: 4.2.0
Error Output:
aditya#Aditya-PC:~/testRails/blog$ rails g controller pages
Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring.
/var/lib/gems/2.1.0/gems/railties-4.2.0/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `active_record' for #<Rails::Application::Configuration:0x00000002ec6c40> (NoMethodError)
from /home/aditya/testRails/blog/config/application.rb:24:in `<class:Application>'
from /home/aditya/testRails/blog/config/application.rb:10:in `<module:Blog>'
from /home/aditya/testRails/blog/config/application.rb:9:in `<top (required)>'
from /var/lib/gems/2.1.0/gems/spring-1.3.6/lib/spring/application.rb:82:in `require'
from /var/lib/gems/2.1.0/gems/spring-1.3.6/lib/spring/application.rb:82:in `preload'
from /var/lib/gems/2.1.0/gems/spring-1.3.6/lib/spring/application.rb:143:in `serve'
from /var/lib/gems/2.1.0/gems/spring-1.3.6/lib/spring/application.rb:131:in `block in run'
from /var/lib/gems/2.1.0/gems/spring-1.3.6/lib/spring/application.rb:125:in `loop'
from /var/lib/gems/2.1.0/gems/spring-1.3.6/lib/spring/application.rb:125:in `run'
from /var/lib/gems/2.1.0/gems/spring-1.3.6/lib/spring/application/boot.rb:18:in `<top (required)>'
from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
EDIT: I removed rails completely and again installed. But no effect, still having this error.
Have you tried to run bundle install in the application?
According to the error seems like you created a new rails app without activerecord
'method_missing': undefined method 'active_record' for #Rails::Application::Configuration
the stack trace is hinting at /home/aditya/testRails/blog/config/application.rb:24
If removing activerecord is intentional follow along to remove anything that is related to activerecord, if not continue reading as you might figure out what went missing ;)
remove any activerecord config from application.rb or environments/*
check your config/application.rb if
require 'rails/all is present, remove it and add the railties that you need like:
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_job/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
# require "railtie/active_record"
remove any adapter from the Gemfile (mysql2, pg, sqlite3)
remove config/database.yml
Hope it helps :)
Related
My app is on:
ruby-2.6.4
Rails 4.2.8
activerecord-4.2.8
I'm upgrading a rails app to ruby-2.6.4 When running a rake task in development, for testing, I am getting errors for BigDecimal() and .../vendor/bundle/ruby/2.6.0/gems/ruby-oci8/...
ArgumentError: invalid value for BigDecimal(): "0.E+00"
/sha/git/sha_human_resources/shared/bundle/ruby/2.6.0/gems/ruby-oci8-2.1.8/lib/oci8/bindtype.rb:35:in `BigDecimal'
...
.../vendor/bundle/ruby/2.6.0/gems/ruby-oci8-2.1.8/lib/oci8/bindtype.rb:216: warning: constant ::Fixnum is deprecated
.../vendor/bundle/ruby/2.6.0/gems/ruby-oci8-2.1.8/lib/oci8/bindtype.rb:219: warning: constant ::Bignum is deprecated
.../vendor/bundle/ruby/2.6.0/gems/ruby-oci8-2.1.8/lib/oci8/compat.rb:73: warning: constant ::Fixnum is deprecated
I found a couple threads about updating the bigdecimal and oci8 gems, so tried a couple versions and found these helped: git diff Gemfile:
-gem 'ruby-oci8', '~> 2.1.5'
+gem 'ruby-oci8', '~> 2.2.8'
and added a bigdecimal gem:
+gem "bigdecimal", ">= 2.0.0"
Now when I run my rake task, I get this error:
rake aborted!
NoMethodError: undefined method `new' for BigDecimal:Class
.../vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.8/lib/active_support/core_ext/object/duplicable.rb:111:in `<class:BigDecimal>'
.../vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.8/lib/active_support/core_ext/object/duplicable.rb:106:in `<top (required)>'
.../vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.8/lib/active_support/core_ext/object.rb:3:in `require'
.../vendor/bundle/ruby/2.6.0/gems/activesupport-4.2.8/lib/active_support/core_ext/object.rb:3:in `<top (required)>'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/configuration.rb:2:in `require'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/configuration.rb:2:in `<top (required)>'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/railtie.rb:2:in `require'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/railtie.rb:2:in `<top (required)>'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/engine.rb:1:in `require'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/engine.rb:1:in `<top (required)>'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/application.rb:7:in `require'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/application.rb:7:in `<top (required)>'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails.rb:11:in `require'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails.rb:11:in `<top (required)>'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/all.rb:1:in `require'
.../vendor/bundle/ruby/2.6.0/gems/railties-4.2.8/lib/rails/all.rb:1:in `<top (required)>'
.../config/application.rb:3:in `require'
.../config/application.rb:3:in `<top (required)>'
.../Rakefile:6:in `require'
.../Rakefile:6:in `<top (required)>'
/usr/local/rvm/rubies/ruby-2.6.4/bin/bundle:30:in `block in <main>'
/usr/local/rvm/rubies/ruby-2.6.4/bin/bundle:22:in `<main>'
/usr/local/rvm/gems/ruby-2.6.4/bin/ruby_executable_hooks:24:in `eval'
/usr/local/rvm/gems/ruby-2.6.4/bin/ruby_executable_hooks:24:in `<main>'
Doing more Google surfing, I found there is not a lot of info on solving this. I did see a couple mentions of upgrading to the latest version of rails. Is this a must to solve this? Is there a monkeypatch or fix out there that can solve/fix/prevent this until we are ready to upgrade our rails version? I feel we will always be chasing the carrot-on-the-stick that is the latest version of rails.
Thanks for any advice.
As per the documentation of BigDecimal, for all Ruby versions 2.6.x, you should be using BigDecimal with a specific version:
The differences among versions are given below:
version characteristics Supported ruby version range
2.0.0 You cannot use BigDecimal.new and do subclassing 2.4 ..
1.4.x BigDecimal.new and subclassing always prints warning. 2.3 .. 2.6
1.3.5 You can use BigDecimal.new and subclassing without warning .. 2.5
You can select the version you want to use using gem method in Gemfile or scripts. For example, you want to stick bigdecimal version 1.3.5, it works file to put the following gem call in you Gemfile.
gem 'bigdecimal', '1.3.5'
In my current project, I am not able to run any of the test case because I am getting the following error:
/home/harsh/Documents/viburnix/cloud/viburnix/spec/support/helpers.rb:2:in `block in <top (required)>': uninitialized constant Features (NameError)
Full trace:
/home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/http/mime_type.rb:163: warning: already initialized constant Mime::ZIP
/home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/http/mime_type.rb:163: warning: previous definition of ZIP was here
Coverage report generated for RSpec to /home/harsh/Documents/viburnix/cloud/viburnix/coverage. 11 / 56 LOC (19.64%) covered.
/home/harsh/Documents/viburnix/cloud/viburnix/spec/support/helpers.rb:2:in `block in <top (required)>': uninitialized constant Features (NameError)
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core.rb:112:in `configure'
from /home/harsh/Documents/viburnix/cloud/viburnix/spec/support/helpers.rb:1:in `<top (required)>'
from /home/harsh/Documents/viburnix/cloud/viburnix/spec/spec_helper.rb:16:in `block in <top (required)>'
from /home/harsh/Documents/viburnix/cloud/viburnix/spec/spec_helper.rb:16:in `each'
from /home/harsh/Documents/viburnix/cloud/viburnix/spec/spec_helper.rb:16:in `<top (required)>'
from /home/harsh/Documents/viburnix/cloud/viburnix/spec/models/user_spec.rb:1:in `require'
from /home/harsh/Documents/viburnix/cloud/viburnix/spec/models/user_spec.rb:1:in `<top (required)>'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `load'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `block in load_spec_files'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `each'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/configuration.rb:932:in `load_spec_files'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/command_line.rb:21:in `run'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/runner.rb:100:in `run'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/lib/rspec/core/runner.rb:31:in `invoke'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/gems/rspec-core-3.0.0.beta2/exe/rspec:4:in `<top (required)>'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/bin/rspec:23:in `load'
from /home/harsh/Documents/viburnix/cloud/viburnix/vendor/ruby/2.1.0/bin/rspec:23:in `<main>'
spec/spec_helper.rb is the standard file generated by spec:install and includes:
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
In spec/support/helpers.rb, I have:
RSpec.configure do |config|
config.include Features::SessionHelpers, type: :feature
config.include Mongoid::Matchers, type: :model
config.include AuthenticationHelpers, type: :controller
end
And it gives error on line 2: Features::SessionHelpers.
Seems like it is either not requiring the code at all or just not loading in correct order.
The problem is that in a team of 7, I am the only one who is not able to run spec. Any help or direction is much needed and would be appreciated.
Sorry for late reply. This project was started by another team and yes all the files, modules and classes were present at right place. The problem was the sequence of loading/requiring (in spec_helper.rb) these files. While other people were working happily without any issue, I had to load/require some of the required files earlier.
What baffles me are 2 questions:
I am not puzzled it didn't work for me. The requiring of those specific files manually make sense and should have been that way from the start. I am puzzled at how did it work for other people?
I tried making a virtual machine exactly the same way as other people. Yet I faced the issue, debunking the myth that this has to do with OS or shell etc.
I have added those lines to spec_helper.rb and I comment them after running tests but before committing my work.
I was playing around with bundler and binstubs and "rake rails:update:bin" and the next time I tried to run rails s i got this exception:
`inherited': undefined method `application' for Rails:Module (NoMethodError)
The same exception appears even for new projects that I create and try to run.
Here's the full text:
C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:63:in `inherited': undefined method `application' for Rails:Module (NoMethodError)
from F:/aptana projects/testy/config/application.rb:10:in `<module:Testy>'
from F:/aptana projects/testy/config/application.rb:9:in `<top (required)>'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:76:in `require'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:76:in `block in <top (required)>'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Well, a few minutes after posting this I tried:
gem uninstall railties
and then again
bundle install
and it resolved the issue. I still have no idea what might have happened in the first place though.
After upgrading to vmc 0.4.4 I can't do push on my Sinatra app anymore
Any known fixes?
Time of crash:
2012-12-06 13:14:20 -0800
NoMethodError: undefined method `changed?' for #
vmc-0.4.4/lib/vmc/cli/app/push/sync.rb:13:in display_changes'
vmc-0.4.4/lib/vmc/cli/app/push.rb:89:insync_app'
vmc-0.4.4/lib/vmc/cli/app/push.rb:80:in push'
mothership-0.3.4/lib/mothership/base.rb:61:inrun'
mothership-0.3.4/lib/mothership/command.rb:68:in block in invoke'
manifests-vmc-plugin-0.4.17/lib/manifests-vmc-plugin/plugin.rb:113:incall'
manifests-vmc-plugin-0.4.17/lib/manifests-vmc-plugin/plugin.rb:113:in block (2 levels) in <class:Manifests>'
mothership-0.3.4/lib/mothership/callbacks.rb:74:inwith_filters'
manifests-vmc-plugin-0.4.17/lib/manifests-vmc-plugin/plugin.rb:112:in block in <class:Manifests>'
mothership-0.3.4/lib/mothership/command.rb:78:ininstance_exec'
mothership-0.3.4/lib/mothership/command.rb:78:in block (2 levels) in invoke'
mothership-0.3.4/lib/mothership/command.rb:82:ininstance_exec'
mothership-0.3.4/lib/mothership/command.rb:82:in invoke'
mothership-0.3.4/lib/mothership/base.rb:50:inexecute'
vmc-0.4.4/lib/vmc/cli.rb:106:in execute'
mothership-0.3.4/lib/mothership.rb:45:instart'
vmc-0.4.4/bin/vmc:11:in <top (required)>'
ruby-1.9.2-p290#main1.9/bin/vmc:23:inload'
ruby-1.9.2-p290#main1.9/bin/vmc:23:in `'
If you experience any issues with vmc 0.4.x at all, I advice you install the legacy version (0.3.23). You can remove 0.4.4 entirely or you can call a specific version (0.3.23 in this case) using the following syntax..
vmc _0.3.23_ <command>
I am running on windows vista 64 bit operating system. Geografikos is a large project created as a masters thesis project by Jeremy Witmer. It is all coded in JRuby. I am currently expanding the project under his guidance however I cannot run his program. The following gems have been installed:
C:\work\Code\geografikos>jruby -S gem list
*** LOCAL GEMS ***
actionmailer (2.3.3)
actionpack (2.3.3)
activerecord (2.3.3)
activerecord-jdbc-adapter (0.9.1)
activerecord-jdbcmysql-adapter (0.9.1)
activeresource (2.3.3)
activesupport (2.3.3)
gchart (1.0.0)
google-geocode (1.2.1)
hoe (2.3.3)
hpricot (0.6.161)
jdbc-mysql (5.0.4)
jruby-openssl (0.5.1)
minitest (1.4.2)
nokogiri (1.3.3)
rack (1.0.0)
rails (2.3.3)
rake (0.8.7)
rc-rest (3.0.0)
rdoc (2.4.3)
rspec (1.2.6)
rubyforge (1.0.4)
rubygems-update (1.3.5)
sources (0.0.1)
geografikos.rb requires the following gems:
%w(rubygems digest/sha1 digest/md5 active_record hpricot yaml open-uri ostruct java google_geocode gchart active_record/fixtures).each{|f| require f}
I get the following error when I require or run geografikos.rb:
C:\work\Code\geografikos>jirb
irb(main):001:0> require 'geografikos'
LoadError: Could not open any of [xml2, xslt, exslt]
from C:/jruby-1.3.1/bin/../lib/ruby/1.8/ffi/library.rb:18:in `ffi_lib'
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/nokogiri-1.3.3-java/lib/nokogiri/ffi/libxml.rb:5
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/nokogiri-1.3.3-java/lib/nokogiri/ffi/libxml.rb:31:in `require'
from C:/jruby-1.3.1/bin/../lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:156:in `require'
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:521:in `new_constants_in
'
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:156:in `require'
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/nokogiri-1.3.3-java/lib/nokogiri.rb:10
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/nokogiri-1.3.3-java/lib/nokogiri.rb:31:in `require'
from C:/jruby-1.3.1/bin/../lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:156:in `require'
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:521:in `new_constants_in
'
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:156:in `require'
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/rc-rest-3.0.0/lib/rc_rest.rb:3
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/rc-rest-3.0.0/lib/rc_rest.rb:31:in `require'
from C:/jruby-1.3.1/bin/../lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:156:in `require'
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:521:in `new_constants_in
'
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:156:in `require'
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/google-geocode-1.2.1/lib/google_geocode.rb:2
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/google-geocode-1.2.1/lib/google_geocode.rb:36:in `require'
from C:/jruby-1.3.1/bin/../lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:156:in `require'
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:521:in `new_constants_in
'
from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:156:in `require'
from geografikos.rb:304
from geografikos.rb:304:in `each'
from geografikos.rb:304
from geografikos.rb:2:in `require'
from (irb):2irb(main):002:0>
I have a feeling that I need to install the xml, xml2, xslt, and exslt libraries but I get an error when I attempt to install these which is shown below:
C:\work\Code\geografikos>jruby -S gem install libxml-ruby
Building native extensions. This could take a while...
ERROR: Error installing libxml-ruby:
ERROR: Failed to build gem native extension.
C:/jruby-1.3.1/bin/../bin/jruby.bat extconf.rb
C:/jruby-1.3.1/bin/../lib/ruby/1.8/mkmf.rb:7: JRuby does not support native extensions. Check wiki.jruby.org for alternatives. (No
tImplementedError)
from C:/jruby-1.3.1/bin/../lib/ruby/1.8/mkmf.rb:14:in `require'
from extconf.rb:14
Gem files will remain installed in C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/libxml-ruby-1.1.3 for inspection.
Results logged to C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/libxml-ruby-1.1.3/ext/libxml/gem_make.out
Please let me know if you need any other information. I cannot solve this problem!
It appears that those gems are implemented "natively"; that is, in a low-level language rather than directly in Ruby. JRuby does not support gems with native extensions because it can't run them in the JVM.