Yunqing
Yunqing

Reputation: 35

When run rails server got a lots of errors

I created a ruby on rails project at /home/web/Rubyonrails

When run rails server then got below errors:

    web@web-VirtualBox:~/Rubyonrails$ rails server
/home/web/Rubyonrails/config/application.rb:19:in `block in <top (required)>': undefined local variable or method `config' for main:Object (NameError)
    from /home/web/Rubyonrails/config/application.rb:18:in `tap'
    from /home/web/Rubyonrails/config/application.rb:18:in `<top (required)>'
    from /home/web/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:88:in `require'
    from /home/web/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:88:in `block in server'
    from /home/web/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `tap'
    from /home/web/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `server'
    from /home/web/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    from /home/web/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands.rb:18:in `<top (required)>'
    from /home/web/Rubyonrails/bin/rails:9:in `require'
    from /home/web/Rubyonrails/bin/rails:9:in `<top (required)>'
    from /home/web/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `load'
    from /home/web/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `call'
    from /home/web/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client/command.rb:7:in `call'
    from /home/web/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client.rb:30:in `run'
    from /home/web/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/bin/spring:49:in `<top (required)>'
    from /home/web/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `load'
    from /home/web/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `<top (required)>'
    from /home/web/Rubyonrails/bin/spring:15:in `require'
    from /home/web/Rubyonrails/bin/spring:15:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

config/application.rb file:

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 Rubyonrails
  class Application < Rails::Application
    # 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.
  end
end

# Bower asset paths
Rails.root.join('vendor', 'assets', 'bower_components').to_s.tap do |bower_path|
  config.sass.load_paths << bower_path
  config.assets.paths << bower_path
end
# Precompile Bootstrap fonts
config.assets.precompile << %r(bootstrap-sass/assets/fonts/bootstrap/[\w-]+\.(?:eot|svg|ttf|woff2?)$)
# Minimum Sass number precision required by bootstrap-sass
::Sass::Script::Value::Number.precision = [8, ::Sass::Script::Value::Number.precision].max

Rubyonrails/bin/rails file looks like:

#!/usr/bin/env ruby
begin
  load File.expand_path('../spring', __FILE__)
rescue LoadError => e
  raise unless e.message.include?('spring')
end
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'

Rubyonrails/bin/spring file looks like:

#!/usr/bin/env ruby

# This file loads spring without using Bundler, in order to be fast.
# It gets overwritten when you run the `spring binstub` command.

unless defined?(Spring)
  require 'rubygems'
  require 'bundler'

  lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
  spring = lockfile.specs.detect { |spec| spec.name == "spring" }
  if spring
    Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
    gem 'spring', spring.version
    require 'spring/binstub'
  end
end

Upvotes: 0

Views: 1857

Answers (3)

the Tin Man
the Tin Man

Reputation: 160551

If you have to run

source /home/web/.rvm/scripts/rvm

every time you open a window then you haven't installed RVM correctly.

Carefully read "Installing RVM" and confirm you followed those steps.

Once you've confirmed that the installation is correct you need to set a default Ruby for RVM to use. First, list the Rubyies RVM manages:

rvm list

which returns something like:

rvm rubies

=* ruby-2.4.0 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

then tell RVM to use one:

rvm use ruby-2.4.0 --default

Also, it's a good idea to periodically tell RVM to update itself. Run

rvm help get

at the command-line for more information.

Upvotes: 0

Mihir Kumar Thakur
Mihir Kumar Thakur

Reputation: 393

In application.rb

# Bower asset paths
root.join('vendor', 'assets', 'bower_components').to_s.tap do |bower_path|
  config.sass.load_paths << bower_path
  config.assets.paths << bower_path
end 

you are missing Rails before root:

# Bower asset paths
Rails.root.join('vendor', 'assets', 'bower_components').to_s.tap do |bower_path|
  config.sass.load_paths << bower_path
  config.assets.paths << bower_path
end

Upvotes: 1

spickermann
spickermann

Reputation: 106872

Change line 18 of your config/application.rb to:

Rails.root.join('vendor', 'assets', 'bower_components').to_s.tap do |bower_path|

root is not defined, but Rails.root is.

Upvotes: 1

Related Questions