我在/ home / web / Rubyonrails
上创建了一个ruby on rails项目当运行rails服务器然后得到以下错误:
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文件:
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文件如下所示:
#!/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文件如下:
#!/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
答案 0 :(得分:1)
将18
的第config/application.rb
行更改为:
Rails.root.join('vendor', 'assets', 'bower_components').to_s.tap do |bower_path|
root
未定义,但Rails.root
是。
答案 1 :(得分:1)
在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
Rails
之前您遗失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
答案 2 :(得分:0)
如果你必须运行
source /home/web/.rvm/scripts/rvm
每次打开窗口时,您都无法正确安装RVM。
仔细阅读&#34; Installing RVM&#34;并确认你遵循了这些步骤。
一旦确认安装正确,就需要设置默认的Ruby for RVM。首先,列出Rubyies RVM管理:
rvm list
返回类似的内容:
rvm rubies
=* ruby-2.4.0 [ x86_64 ]
# => - current
# =* - current && default
# * - default
然后告诉RVM使用一个:
rvm use ruby-2.4.0 --default
此外,定期告诉RVM更新自己也是一个好主意。运行
rvm help get
在命令行中获取更多信息。