2017-03-10 104 views
0

的我在的/ home /網絡/ Rubyonrails當運行軌道服務器得到了很多錯誤

當運行軌道服務器然後得到下面的錯誤創建on Rails項目紅寶石:

[email protected]:~/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>' 

配置/應用。 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 /斌/導軌文件看起來像:

#!/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 /斌/春文件看起來像:

#!/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

你的'config/application.rb'文件是怎麼樣的 - 特別是在第18行左右? – spickermann

+0

我粘貼在我的帖子上面以供參考。 – Yunqing

+0

請閱讀「[問]」,包括鏈接的頁面。你在問兩個似乎無關的問題。不要這樣做,因爲它會導致無關的答案。相反,問一個具體問題,或者兩個非常密切相關的問題。 –

回答

1

行更改您的config/application.rb18

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

root沒有定義,但Rails.root是。

+0

感謝您的幫助!我已經解決了這個問題! – Yunqing

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 

你缺少Railsroot

# 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 
+0

感謝您的回覆。我在root之前添加了Rails,但仍然是相同的錯誤。 – Yunqing

+0

感謝您的幫助!我已經解決了這個問題! – Yunqing

0

如果你需要運行

source /home/web/.rvm/scripts/rvm 
每次打開一個窗口,那麼你的避風港時間

沒有正確安裝RVM。

仔細閱讀「Installing RVM」並確認您已按照這些步驟操作。

確認安裝正確後,您需要設置一個默認的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 

at the command-line for more information。

+0

非常感謝!它解決了我的RVM問題。我重新安裝RVM。但是當我運行rails server時,錯誤信息仍然是一樣的。我編輯application.rb跟隨其他人的建議,像這樣Rails.root.join('vendor','assets','bower_components')。to_s.tap do | bower_path | – Yunqing

+0

感謝您的幫助!我已經解決了這個問題! – Yunqing

相關問題