0

I'm trying to follow a rails tutorial and managed to run bundle install. Upon running rails s, however, I get the following error.

Users/abc/.rvm/gems/ruby-2.4.1@railstutorial_rails_4_0/gems/railties-4.0.8/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `load_defaults' for #<Rails::Application::Configuration:0x007fc29e53d7a8> (NoMethodError)
from /Users/abc/Desktop/Rails_Projects/sample_app/config/application.rb:12:in `<class:Application>'
from /Users/abc/Desktop/Rails_Projects/sample_app/config/application.rb:10:in `<module:SampleApp>'
from /Users/abc/Desktop/Rails_Projects/sample_app/config/application.rb:9:in `<top (required)>'
from /Users/abc/.rvm/gems/ruby-2.4.1@railstutorial_rails_4_0/gems/railties-4.0.8/lib/rails/commands.rb:74:in `require'
from /Users/abc/.rvm/gems/ruby-2.4.1@railstutorial_rails_4_0/gems/railties-4.0.8/lib/rails/commands.rb:74:in `block in <top (required)>'
from /Users/abc/.rvm/gems/ruby-2.4.1@railstutorial_rails_4_0/gems/railties-4.0.8/lib/rails/commands.rb:71:in `tap'
from /Users/abc/.rvm/gems/ruby-2.4.1@railstutorial_rails_4_0/gems/railties-4.0.8/lib/rails/commands.rb:71:in `<top (required)>'
from bin/rails:9:in `require'
from bin/rails:9:in `<main>'

This is my gemfile

source 'https://rubygems.org'
ruby '2.4.1'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.8'
group :development, :test do
    gem 'sqlite3'
    gem 'rspec-rails', '2.13.1'
end
group :test do
    gem 'selenium-webdriver', '2.35.1'
    gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.3'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
    gem 'sdoc', '0.3.20', require: false
end
group :production do
    gem 'pg', '0.15.1'
    gem 'rails_12factor', '0.0.2'
end

Thanks in advance

EDIT:

This is my config/application.rb file. I've noticed that the error occurs at

'config.load_defaults 5.1'. I've read another answer that suggests deleting this line but this causes more issues for me.

require_relative 'boot'

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module MhApp
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.1

    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.
    config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)

  end
end
user7215621
  • 63
  • 1
  • 1
  • 4
  • Can you also include the content of your `config/application.rb` file? – DanneManne Nov 23 '17 at 03:05
  • Hi, I've just edited my question and posted the contents of the file. I've managed to track down where the error is happening though I'm not sure how to fix it. – user7215621 Nov 23 '17 at 03:10
  • Try reading through this question: I see your gem file specifies Rails 4.0.8 but your config/application.rb file looks like it’s from a newer version of Rails. PErhaps you locally did Rails new with a newer version then updated your gem file to say 4.0.8 – inveterateliterate Nov 23 '17 at 03:16
  • https://stackoverflow.com/questions/22977051/error-launching-rails-server-undefined-method-configure < this question. Meant to link above – inveterateliterate Nov 23 '17 at 03:17
  • 2
    Possible duplicate of [error "Undefinded method "load\_defaults" " when trying to deploy app on Heroku](https://stackoverflow.com/questions/43813749/error-undefinded-method-load-defaults-when-trying-to-deploy-app-on-heroku) – max pleaner Nov 23 '17 at 03:56
  • comment line `config.load_defaults 5.1` and try – puneet18 Nov 23 '17 at 05:08

2 Answers2

0

try this gem install bundler

and then run

bundle install

Regolith
  • 2,944
  • 9
  • 33
  • 50
Parul Kanani
  • 111
  • 9
0

You have to change your rails version, when you create a new app it has created in rails 5.1 version (maybe) check your rails version first and update that in gem file.

Check your rails version with this command rails -v And then update your version in gem file then you have to give bundle install

Hope this will help you.

Ami
  • 19
  • 11