rails console gives method_missing, undefined - ruby-on-rails

I am following a Rails tutorial and have to run rails console. I never had a issue with it before but now it doesn't run.
Here's the error.
/Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.11/lib/rails/railtie/configuration.rb:85:in `method_missing': undefined method `generators' for
#<Rails::Railtie::Configuration:0x007ffc41d4a9a0> (NoMethodError)
from /Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/rspec-rails-2.0.0.beta.18/lib/rspec-rails.rb:4:in `<class:Railtie>'

I noticed that your rspec gem is the same version as listed here: "rails generate rspec:install" seems to be failing
Maybe that will help.

Related

Rspec errors: Unable to find (erb) to read failed line

my Rspec in rails suddenly got weird errors.
it said
Failure/Error: Unable to find (erb) to read failed line
NoMethodError:
undefined method `id' for nil:NilClass
# (erb):63:in `get_binding'
to most of my test spec and it said the same thing, any one can help me please? thank you :)
note: i`m using rspec-rails 3.4.2 and my version rails is 4.2.5.2

Trouble with new rails app

I have just created a new rails app (on the CL, using rails new), I am on 4.2.6, but it seems like before I can do anything to the app that i've hit errors.
first...
/config/environments/development.rb:53:in `block in <top (required)>':
uninitialized constant ActiveSupport::EventedFileUpdateChecker (NameError)
then once I comment that out...
/config/initializers/new_framework_defaults.rb:15:in `<top (required)>':
undefined method `to_time_preserves_timezone=' for ActiveSupport:Module (NoMethodError)
and once that is commented out...
/config/initializers/new_framework_defaults.rb:21:in `<top (required)>':
undefined method `halt_callback_chains_on_return_false=' for ActiveSupport:Module (NoMethodError)
and lastly...
.gem/ruby/2.2.3/gems/actionmailer-4.2.5/lib/action_mailer/base.rb:569:in `method_missing':
undefined method `perform_caching=' for ActionMailer::Base:Class (NoMethodError)
everything I can turn up on Google suggests these are Rails 5 related things. I'm not sure how to get around them, or how to create an app that is still specific to 4.2.6.
If still you want to use Rails 5 comment the below line in development.rb file:
config.action_mailer.perform_caching = false
And after doing that you may get:
ActionView::Template::Error (couldn't find file 'ation_cable' with type 'application/javascript'
Then remove = from //= require action_cable in your cable.js file.
tl;dr: Re-create your Rails project, providing the specific Rails version.
To elaborate on Peter's answer: often this error occurs because you have a newer version of Rails installed than the one called for in your .railsrc or template.rb.
If this is the case, when you run rails new my_new_app, the newest version is used by default for the earlier steps of the process, but then once the template/railsrc version is installed, latter steps use this version. This causes compatibility issues.
You can verify that this is your problem by comparing the output of rails -v (in the directory where you called rails new) with what's in your .railsrc or template.rb. If they are different, there is an easy fix:
Recreate your Rails app, specifying the same Rails version from your .railsrc or template.rb in the command line call:
rails _4.2.5.1_ new my_new_app

mongoid and kaminari throws undefined method page

When using kaminari with mongoid, I get the error
undefined method `page' for #<Mongoid::Contextual::Mongo:0x007fe48c195af0>
Not sure what is wrong. I even tried running
Item.page(params[:page])
and I get the error
NoMethodError: undefined method `page' for Item:Class
The gem is present in the Gemfile. Double checked.
I see you are using mongoid, in that case add to the Gemfile will_paginate_mongoid gem and run $ bundle
More info can be found here and here.

undefined method rails 3.2.9 and devise 1.0.11

Error:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/devise-1.0.11/lib/devise.rb:89:in '': undefined method 'weeks' for 2:Fixnum (NoMethodError)
That error is thrown whenever I try to run 'rails g devise:install' in a rails project I've been working on.
Any ideas?
P.S. requiring gem 'devise' in Gemfile and running bundle install to get the devise gem
This issue was already dealt with here. Try updating to a later devise version to fix.

Undefined method `mass_assignment_sanitizer=' for ActiveRecord::Base:Class (NoMethodError)

I'm learning Rails with the awesome Ruby on Rails Tutorial by Michael Hartl. I'm on section 3.2.2 (Test Driven Development) in which I need to run the following command to run the rspec tests for my Rails project:
bundle exec rspec spec/
But it doesn't work. Instead I get this error:
/Users/mh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/
activerecord-3.1.3/lib/active_record/base.rb:1088:in `method_missing':
undefined method `mass_assignment_sanitizer=' for
ActiveRecord::Base:Class (NoMethodError)
I've tried reinstalling rspec and changing my Gemfile, but nothing appeases the undefined method error!
Did you downgrade from Rails 3.2 RC1? Comment out the following two lines from your development.rb:
config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5
While m818's answer will solve the problem, you might still get errors if you are tyring to use deprecated methods elsewhere in your code.
I had the same problem, commenting out those lines got rid of some errors, but not all of them, anywhere I was using attr_accessible gave me the same error.
It turned out to be the `active_record' gem that was updated to 4.0 when I didn't want it to. Since I'm using a Padrino app, I had to do this in the Gemfile:
gem 'activerecord', '= 3.2.12', :require => "active_record"
That solved all issues and I didn't have to comment out the lines in database.rb.

Resources