2016-09-11 67 views
15

我有一個rails應用程序(rails 5)。在發展中,一切工作,當我使用生產中的Rails控制檯:NameError:未初始化的常量

rails console 

,並輸入指令,例如User.all,它的工作。

在生產中,我的應用程序的工作完全沒有問題,沒有錯誤,但是當我使用rails console production和例如User.all進入我有一個錯誤:

NameError: uninitialized constant User 
    from (irb):2 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in `start' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require' 
    from /home/alexandre/tcheen/bin/rails:9:in `<top (required)>' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/commands/rails.rb:6:in `load' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/commands/rails.rb:6:in `call' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/command_wrapper.rb:38:in `call' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/application.rb:191:in `block in serve' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/application.rb:161:in `fork' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/application.rb:161:in `serve' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/application.rb:131:in `block in run' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/application.rb:125:in `loop' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/application.rb:125:in `run' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/application/boot.rb:19:in `<top (required)>' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
    from /home/alexandre/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
    from -e:1:in `<main>' 

我有我的所有類的同樣的問題,但我再說一遍,該應用程序完美地工作。 我在Mac OS上開發,應用程序在debian 8上運行。 我的模型被正確命名爲i verified。 謝謝

+0

如果你輸入':: User.all',它會工作嗎? – xuanduc987

+0

謝謝,但它在新的ssh會話後工作 – Alexandre

+0

突然出現這個問題。不知道發生了什麼 – rewolf

回答

45

我有這個問題,並意識到它發生後,我調整了我的一個工作文件。 什麼修復它重新啓動彈簧裝載機。只要運行

spring stop 

那麼下次你運行rails console它應該加載的東西是正常的。

+1

你是如此的生命保護者!自3個多星期以來,我一直陷在這個問題上。你真的爲我保存:) –

+1

@JagjotSingh對不起,你沒有看到它更快!它也困擾了我很長一段時間!很高興它幫助你,但現在! – rewolf

+0

在這一個上失去了一些灰色頭髮。謝謝。 – dps

相關問題