uninitialized constant ActiveRecord from exception_notification gem - ruby-on-rails

I Am using exception notifier like this in my rails 3.0.7-
gem 'exception_notification_rails3', :require => 'exception_notifier'
This application uses mongoid rather than ActiveRecord. But when I try to open rails c, it give following error -
Could not load SystemTimer >= v1.2.0. Falling back to timeout.rb. SystemTimer is STRONGLY recommended for timeouts in Ruby 1.8.7. See http://ph7spot.com/blog/system-timer-1-2-release for details.
/var/lib/gems/1.8/gems/exception_notification_rails3-1.2.0/lib/exception_notifier.rb:8:in `default_ignore_exceptions': uninitialized constant ActiveRecord::RecordNotFound (NameError)
from /var/lib/gems/1.8/gems/exception_notification_rails3-1.2.0/lib/exception_notifier.rb:7:in `tap'
from /var/lib/gems/1.8/gems/exception_notification_rails3-1.2.0/lib/exception_notifier.rb:7:in `default_ignore_exceptions'
from /var/lib/gems/1.8/gems/exception_notification_rails3-1.2.0/lib/exception_notifier.rb:30:in `initialize'
from /var/lib/gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:33:in `new'
from /var/lib/gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:33:in `build'
from /var/lib/gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in `build'
from /var/lib/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:209:in `inject'
from /var/lib/gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in `each'
from /var/lib/gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in `inject'
from /var/lib/gems/1.8/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in `build'
from /var/lib/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:162:in `build_middleware_stack'
from /var/lib/gems/1.8/gems/railties-3.0.7/lib/rails/application/finisher.rb:35
from /var/lib/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `instance_exec'
from /var/lib/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `run'
from /var/lib/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:50:in `run_initializers'
from /var/lib/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `each'
from /var/lib/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `run_initializers'
from /var/lib/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:134:in `initialize!'
from /var/lib/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:77:in `send'
from /var/lib/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
from /home/rtdp/workspace/bids/config/environment.rb:5
from /var/lib/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:103:in `require_environment!'
from /var/lib/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:22
from script/rails:6:in `require'
from script/rails:6
I tried googling over this, but couldn't find anything related.
Thanks.
UPDATE -
I just checked in /var/lib/gems/1.8/gems/exception_notification_rails3-1.2.0/lib/exception_notifier.rb file. This file has code -
exceptions << ActiveRecord::RecordNotFound if defined? ActiveRecord
So commented this, and checked. Now the system works. So this means my active record is being declared somewhere. I reconfirmed this on console.
My application.rb file has this -
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
Now, what might be causing to include the ActiveRecord and then failing the Exception Notifier ?

People, http://github.com/rails/exception_notification is no longer the official exception_notification repo. See the note on the home page.
The official repo lies now on http://github.com/smartinez87/exception_notification
If you do gem install exception_notification it will pull the gem from there.
This issue is already fixed there, if not please report the issue there.
Thanks!

I found that some other gem was including the ActiveRecord as a dependency, and that was causing this to fail. I removed that gem and everything is fine now.

Erik Hollensbe fixed this error in his personal fork of exception_notifier. His solution worked perfectly for me under Rails 3.0.9 and Ruby 1.9.2p180.

Related

visit_Psych_Nodes_Alias: Unknown alias: default (Psych::BadAlias)

I updated from ruby 2.7.1 to 3.1.1, then removed Gemfile.lock and ran bundle update (it's on a dev branch, so I can throw it away if this is a bad idea, I just wanted to see if it would work).
bundle update succeeds, but when I start the server:
rails s
=> Booting Puma
=> Rails 7.0.2.2 application starting in development
=> Run `bin/rails server --help` for more startup options
Exiting
/Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:430:in `visit_Psych_Nodes_Alias': Unknown alias: default (Psych::BadAlias)
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/visitor.rb:30:in `visit'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/visitor.rb:6:in `accept'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:35:in `accept'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:345:in `block in revive_hash'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `each'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `each_slice'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `revive_hash'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:167:in `visit_Psych_Nodes_Mapping'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/visitor.rb:30:in `visit'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/visitor.rb:6:in `accept'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:35:in `accept'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:345:in `block in revive_hash'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `each'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `each_slice'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:343:in `revive_hash'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:167:in `visit_Psych_Nodes_Mapping'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/visitor.rb:30:in `visit'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/visitor.rb:6:in `accept'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:35:in `accept'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:318:in `visit_Psych_Nodes_Document'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/visitor.rb:30:in `visit'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/visitor.rb:6:in `accept'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:35:in `accept'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych.rb:335:in `safe_load'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/psych.rb:370:in `load'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/webpacker-4.3.0/lib/webpacker/env.rb:30:in `available_environments'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/webpacker-4.3.0/lib/webpacker/env.rb:21:in `current'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/webpacker-4.3.0/lib/webpacker/env.rb:15:in `inquire'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/webpacker-4.3.0/lib/webpacker/env.rb:7:in `inquire'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/webpacker-4.3.0/lib/webpacker/instance.rb:11:in `env'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/webpacker-4.3.0/lib/webpacker/instance.rb:18:in `config'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/webpacker-4.3.0/lib/webpacker.rb:34:in `config'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/webpacker-4.3.0/lib/webpacker/railtie.rb:32:in `block in <class:Engine>'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:32:in `instance_exec'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:32:in `run'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/tsort.rb:228:in `block in tsort_each'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/tsort.rb:347:in `each'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/tsort.rb:347:in `call'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/tsort.rb:347:in `each_strongly_connected_component'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/tsort.rb:226:in `tsort_each'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/3.1.0/tsort.rb:205:in `tsort_each'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:60:in `run_initializers'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/application.rb:372:in `initialize!'
from /Users/st/rails/hangswith/config/environment.rb:5:in `<main>'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:42:in `require_relative'
from config.ru:3:in `block in <main>'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/builder.rb:116:in `eval'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/builder.rb:116:in `new_from_string'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/builder.rb:105:in `load_file'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/builder.rb:66:in `parse_file'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/server.rb:349:in `build_app_and_options_from_config'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/server.rb:249:in `app'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/server.rb:422:in `wrapped_app'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands/server/server_command.rb:76:in `log_to_stdout'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands/server/server_command.rb:36:in `start'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands/server/server_command.rb:143:in `block in perform'
from <internal:kernel>:90:in `tap'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands/server/server_command.rb:134:in `perform'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/command/base.rb:87:in `perform'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/command.rb:48:in `invoke'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands.rb:18:in `<main>'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /Users/st/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from bin/rails:4:in `<main>'
What I've tried
Googling the 'psych' error message reveals this which may be related. But when I search the entire app for YAML.safe_load (or even just safe_load), there are 0 occurrences of it. (perhaps I should be searching actual gems in my app?).
It was a long shot but based on this comment, I ran gem rdoc --all to update all rdoc documentation. But that didn't help.
The problem is related to the Ruby 3.1 / Psych 4.x incompatibility described in this issue: https://bugs.ruby-lang.org/issues/17866
Ruby 3.0 comes with Psych 3, while Ruby 3.1 comes with Psych 4, which has a major breaking change (diff 3.3.2 → 4.0.0).
The new YAML loading methods (Psych 4) do not load aliases unless they get the aliases: true argument.
The old YAML loading methods (Psych 3) do not support the aliases keyword.
At this point, it seems like anyone, anywhere that wants to load YAML in the same way it worked prior to Ruby 3.1, need to do something like this:
begin
YAML.load(source, aliases: true, **options)
rescue ArgumentError
YAML.load(source, **options)
end
as patched by the Rails team.
In your case, I suspect you will need to see which Rails version that matches your major version preference includes this patch before you can upgrade to Ruby 3.1.
Personally, wherever I have control of the code that loads YAML, I am adding an extension like this:
module YAML
def self.properly_load_file(path)
YAML.load_file path, aliases: true
rescue ArgumentError
YAML.load_file path
end
end
or, if I want to completely revert this change done in Psych 4, I add this to my code:
module YAML
class << self
alias_method :load, :unsafe_load if YAML.respond_to? :unsafe_load
end
end
This has the advantage of restoring YAML::load, and YAML::load_file (which uses it) to their original glory, and solves everything including libraries that you have no control of, in all Ruby versions.
Lastly, as I mentioned in the comments, in case you prefer a minimally invasive stopgap measure, you might be able to get away with pinning Psych to < 4 in your Gemfile:
gem 'psych', '< 4'
Note for Rails users (>= 7.0.3.1)
ActiveRecord 7.0.3.1 changed an internal call and it now calls safe_load directly. If you see a Psych related error during rails tests, you might be affected by this change.
To resolve it, you can add this to a new or existing initializer:
# config/initializers/activerecord_yaml.rb
ActiveRecord.use_yaml_unsafe_load = true
You may also use ActiveRecord.yaml_column_permitted_classes to configure the allowed classes instead.
More info in this post.
I ran into the same problem, using a very recent version of rails and ruby 3.1.1 and the suggestion that DannyB mentioned fixed my problem.
In my Gemfile, I put webpacker3 and specified psych < 4. I don't know yet if this version of psych will break something down the road but at least webpacker installed:
gem 'webpacker', '~>3.0'
gem 'psych', '< 4'
In my case I had ruby version 3.0.3 on gem 'rails', '~> 6.1.5'
My default system version was locked to psych (default: 3.3.2) but somehow Gemfile.lock had stuff broken with:
psych (4.0.3)
stringio
sdoc (2.3.1)
rdoc (>= 5.0, < 6.4.0)
The solution was to remove those, then lock correct version of Psych in Gemfile
gem 'psych', '< 4
Then bundle install which fixed the circular broken dependencies
A simple solution: downgrade to ruby 3.0.X
This is simple and easy, requires no code changes, and can be upgraded to ruby 3.1.x in the near future when everything's caught up and is compatible with Psych 4.
Note: ruby 3.0.3 is the latest ruby version which still uses Psych 3.x.x, so there are no problems and everything just works.
Why this solution?
I prefer this option because patching an app or its gems can get complicated and I prefer the simplest/safest solution.
See here and here for the advice that helped me make the decision:
I think it's best to revert to ruby 3.0.3, so as to use the latest ruby version that doesn't use psych 4. Do you think that's a good idea?
Absolutely yes in regards to reverting to Ruby < 3.1 ... it takes time until the gem developers community will update their gems
Why not downgrade psych instead?
The only reason I didn't downgrade psych gem instead of ruby is because I'm not 100% sure that doing so won't cause problems elsewhere, potentially things that are hard to detect. Although it could be a completely viable solution (I'm just not sure that it is, hence I prefer to play it safe and downgrade ruby instead).
in my case, after update to ruby 3.1.2 updating to rails 7.0.4 solved it.

When upgrading from Rails 3.2 to Rails 4, why does rake give 'uninitialized constant ActiveModel::ForbiddenAttributesProtection'?

I am currently attempting to upgrade a Rails 3.2 app to Rails 4. I updated my Gemfile by referencing the correct version of Rails:
gem 'rails', '~>4.0.0'
as well as removing the assets header, per here.
Next, I attempted to run rake rails:update. It gave me this error:
rake aborted!
NameError: uninitialized constant ActiveModel::ForbiddenAttributesProtection
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/attribute_assignment.rb:6:in `<module:AttributeAssignment>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/attribute_assignment.rb:3:in `<module:ActiveRecord>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/attribute_assignment.rb:2:in `<top (required)>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/base.rb:300:in `<class:Base>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/base.rb:281:in `<module:ActiveRecord>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/base.rb:22:in `<top (required)>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/activerecord-4.0.13/lib/active_record/railtie.rb:38:in `block in <class:Railtie>'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie.rb:201:in `instance_exec'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie.rb:201:in `block in run_tasks_blocks'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie.rb:201:in `each'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie.rb:201:in `run_tasks_blocks'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/application.rb:253:in `block in run_tasks_blocks'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/engine/railties.rb:17:in `each'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/engine/railties.rb:17:in `each'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/application.rb:253:in `run_tasks_blocks'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/engine.rb:446:in `load_tasks'
/home/vagrant/.rvm/gems/ruby-2.2.0/gems/railties-4.0.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
/vagrant/Rakefile:7:in `<top (required)>'
(See full trace by running task with --trace)
What is causing this error?
The only place I could find this error online was this GitHub issue.
I searched for ActiveModel::ForbiddenAttributesProtection on that page, and found it here.
As I was reading that comment and following, I found this one, which said:
Rails 3.2 apps can just add strong_parameter gem AFAIK and it would work out of the box.
Looking at my Gemfile again I realized what the problem was. It contained this line:
gem 'strong_parameters'
The problem is that the strong_parameters gem duplicates the Rails 4 way of doing things, allowing newer, better code to be used in Rails 3.2. Thus, it conflicts with the built-in functionality in Rails 4.
I removed that line from my Gemfile, and after running bundle, the rake command worked.
Edit: After restarting unicorn, I was getting a similar error in the log. I deleted config/initializers/strong_parameters.rb, but that didn't seem to help. However, after rebooting my VM, it was working properly.

Rails, Devise, and Mongo - Which versions do I use?

I'm currently trying to get a Mongo database running alongside Devise. I'm using Rails 3.2.2 and Ruby 1.9.3, mongo_mapper 0.11.0, devise 1.1.9, and devise-mongo_mapper 0.0.2. I've referred to numerous sources online, but they seem to be invariably outdated.
A huge problem I'm facing right now involves devise-mongo_mapper. With mongod running on the terminal, trying to run the rails server gives me the following:
/usr/local/lib/ruby/gems/1.9.1/gems/devise-1.1.9/lib/devise.rb:193:in `mailer=': undefined method `ref' for ActiveSupport::Dependencies:Module (NoMethodError)
from /usr/local/lib/ruby/gems/1.9.1/gems/devise-1.1.9/lib/devise.rb:195:in `<module:Devise>'
from /usr/local/lib/ruby/gems/1.9.1/gems/devise-1.1.9/lib/devise.rb:4:in `<top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `block in require'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
from /home/neilbasu/Desktop/rails_practice_app/onemoremongopractice/config/application.rb:13:in `<top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/commands.rb:53:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/commands.rb:53:in `block in <top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/commands.rb:50:in `tap'
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I checked online and found this could be because my devise isn't updated. Trying to update it gave me this:
Bundler could not find compatible versions for gem "devise":
In Gemfile:
devise-mongo_mapper (>= 0) ruby depends on
devise (~> 1.1.0) ruby
devise (2.0.4)
So basically, the older devise won't work, and the newest version isn't compatible with my current devise-mongo_mapper. Is there any way around this? Either a way to get all of these programs working together or a way to not need devise-mongo_mapper at all would be great.
Take a look at several of the forks.
They just bumped the version in the gemspec and the code probably works unchanged.
You can install whatever version of the gem you want using the -v argument.
sudo gem install whatever -v 1.0.1
Or you can look at the forks as Plastic Chicken suggested.
I was also facing the same error and running "bundle update" solved my problem.

Rails 3.2.0 rspec debugger not working

I've just upgraded to ruby 1.9.3-p0 and rails 3.2.0. I'm now trying to debug an error in one of my tests using
rspec spec -d
But I get this error:
/home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:422:in `rescue in debug=': (RuntimeError)
**************************************************
/home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.so: undefined symbol: ruby_threadptr_data_type - /home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.so
If you have it installed as a ruby gem, then you need to either require
'rubygems' or configure the RUBYOPT environment variable with the value
'rubygems'.
/home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/ruby-debug-base19-0.11.25/lib/ruby-debug-base.rb:1:in `require'
/home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/ruby-debug-base19-0.11.25/lib/ruby-debug-base.rb:1:in `<top (required)>'
/home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/ruby-debug19-0.11.6/cli/ruby-debug.rb:5:in `require'
/home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/ruby-debug19-0.11.6/cli/ruby-debug.rb:5:in `<top (required)>'
/home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:408:in `require'
/home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:408:in `debug='
/home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/configuration_options.rb:19:in `block in configure'
/home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/configuration_options.rb:18:in `each'
/home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/configuration_options.rb:18:in `configure'
/home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:21:in `run'
/home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
/home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
/home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun'
**************************************************
from /home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:407:in `debug='
from /home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/configuration_options.rb:19:in `block in configure'
from /home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/configuration_options.rb:18:in `each'
from /home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/configuration_options.rb:18:in `configure'
from /home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:21:in `run'
from /home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
from /home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
from /home/map7/.rvm/gems/ruby-1.9.3-p0#rails3.2/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun'
Install the new debugger gem that works with Ruby 1.9.3 and 1.9.2:
https://github.com/cldwalker/debugger
Stick this in your Gemfile:
# one-liner to install these properly: bash < <(curl -L https://raw.github.com/gist/1333785)
gem 'linecache19', '0.5.13'
gem 'ruby-debug-base19', '0.11.26'
You'll need to run that one-liner in order for bundler to pick up the proper gems.
EDIT: I forgot to link to the posts I used to get debugging working:
ruby-debug with Ruby 1.9.3?
ruby-debug19 on ruby-1.9.3-preview1
I guess I can't comment on other answers yet, but I found many of these instructions don't mention you'll still need to include the
gem 'ruby-debug19', :require => 'ruby-debug'
line in your Gemfile, in addition to the instructions siannopollo provides. Without this, I get a 'cannot load such file -- ruby-debug' error (OSX, rvm, 1.9.3-p125).
FWIW, the gist is hardcoded to 1.9.3-p0, so if you're on 1.9.3-p125, you might need to edit it (also, generally a bad idea to execute a gist you haven't read).
For me, all it took was:
gem 'debugger'
in the Gemfile
Had to upgrade the following
bundle update ruby-debug-base19

Rspec, Spork, & Autotest Error

I'm trying to teach myself rails by going through http://railstutorial.org/. I quit working on the tutorial app last night and then came back to it today. Now I'm getting an error when I start up the Spork server. Here is a trace of the error.
spork Using RSpec Loading Spork.prefork block... can't convert nil into Hash (TypeError) /usr/local/lib/ruby/gems/1.8/gems/activemodel-3.0.0/lib/active_model/validations/validates.rb:90:in merge' /usr/local/lib/ruby/gems/1.8/gems/activemodel-3.0.0/lib/active_model/validations/validates.rb:90:invalidates' /usr/local/lib/ruby/gems/1.8/gems/activemodel-3.0.0/lib/active_model/validations/validates.rb:83:in each' /usr/local/lib/ruby/gems/1.8/gems/activemodel-3.0.0/lib/active_model/validations/validates.rb:83:invalidates' /Users/chietala/Desktop/rails_projects/sample_app/app/models/user.rb:20 /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:454:in load' /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:454:inload_file' /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:591:in new_constants_in' /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:453:inload_file' /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:340:in require_or_load' /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:300:independ_on' /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:216:in require_dependency' /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/engine.rb:138:ineager_load!' /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/engine.rb:137:in each' /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/engine.rb:137:ineager_load!' /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/engine.rb:135:in each' /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/engine.rb:135:ineager_load!' /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/application.rb:108:in eager_load!' /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/application/finisher.rb:41 /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/initializable.rb:25:ininstance_exec' /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/initializable.rb:25:in run' /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/initializable.rb:50:inrun_initializers' /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/initializable.rb:49:in each' /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/initializable.rb:49:inrun_initializers' /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/application.rb:134:in initialize!' /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/application.rb:77:insend' /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.0/lib/rails/application.rb:77:in method_missing' /Users/chietala/Desktop/rails_projects/sample_app/spec/../config/environment.rb:5 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:ingem_original_require' /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in require' /Users/chietala/Desktop/rails_projects/sample_app/spec/spec_helper.rb:10 /usr/local/lib/ruby/gems/1.8/gems/spork-0.8.4/bin/../lib/spork.rb:23:inprefork' /Users/chietala/Desktop/rails_projects/sample_app/spec/spec_helper.rb:4 /usr/local/lib/ruby/gems/1.8/gems/spork-0.8.4/lib/spork/test_framework.rb:138:in load' /usr/local/lib/ruby/gems/1.8/gems/spork-0.8.4/lib/spork/test_framework.rb:138:inpreload' /usr/local/lib/ruby/gems/1.8/gems/spork-0.8.4/lib/spork/app_framework.rb:64:in preload' /usr/local/lib/ruby/gems/1.8/gems/spork-0.8.4/lib/spork/test_framework.rb:134:inpreload' /usr/local/lib/ruby/gems/1.8/gems/spork-0.8.4/bin/../lib/spork.rb:67:in exec_prefork' /usr/local/lib/ruby/gems/1.8/gems/spork-0.8.4/lib/spork/test_framework.rb:120:inpreload' /usr/local/lib/ruby/gems/1.8/gems/spork-0.8.4/lib/spork/run_strategy/forking.rb:25:in preload' /usr/local/lib/ruby/gems/1.8/gems/spork-0.8.4/bin/../lib/spork/runner.rb:74:inrun' /usr/local/lib/ruby/gems/1.8/gems/spork-0.8.4/bin/../lib/spork/runner.rb:9:in run' /usr/local/lib/ruby/gems/1.8/gems/spork-0.8.4/bin/spork:10 /usr/local/bin/spork:19:inload' /usr/local/bin/spork:19
Luckily I am using Git for version control and I was in a separate branch when I received this problem, however switching to the master still results in the error.
I'm not really sure where or how to fix this problem. Anyone have any ideas?
I was using 1.9.2, rails3, and rspec-rails 2.0.0rc with spork-0.8.4 successfully. Then I upgraded to rspec-rails 2.0.0 and had some issues.
I just upgraded my Gemfile to rspec-rails 2.0.1 and spork 0.9.0.rc2 and everything works again!
Gemfile:
gem 'rspec-rails','>= 2.0.1'
gem 'spork', '>= 0.9.0.rc2'
Give that a shot. (You can always switch back to your old version, if it doesn't help.)
Check the spork page on github to see if there are any other things to consider. If you are using 1.8.7 there may be some differences.
If you want the cutting edge (sometimes I do on gems):
gem 'spork', :git => 'http://github.com/timcharper/spork.git'
Maybe there is a fix for your particular combo....
Let me know if this helps!

Resources