为什么我在运行webrick服务器时会得到未初始化的常量设计名称错误?

时间:2011-07-01 18:38:12

标签: ruby-on-rails ruby devise

在我的应用程序中,我使用了ruby 1.9.2和rails 3.0.3并且还安装了Devise gem。问题在我运行Webrick服务器时开始我得到未初始化的常量设计名称错误。

       /home/app/Workspace/project/Library_Management/Library_Management/config/initializers/devise.rb:3:in `<top (required)>': uninitialized constant Devise (NameError)
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/engine.rb:201:in `block (2 levels) in <class:Engine>'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/engine.rb:200:in `each'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/engine.rb:200:in `block in <class:Engine>'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `instance_exec'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `run'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/initializable.rb:50:in `block in run_initializers'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `each'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `run_initializers'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/application.rb:134:in `initialize!'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/application.rb:77:in `method_missing'
from /home/app/Workspace/project/Library_Management/Library_Management/config/environment.rb:5:in `<top (required)>'
from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:54:in `require'
from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:54:in `require'
from /home/app/Workspace/project/Library_Management/Library_Management/config.ru:3:in `block in <main>'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/builder.rb:46:in `instance_eval'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/builder.rb:46:in `initialize'
from /home/app/Workspace/project/Library_Management/Library_Management/config.ru:1:in `new'
from /home/app/Workspace/project/Library_Management/Library_Management/config.ru:1:in `<main>'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/builder.rb:35:in `eval'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/builder.rb:35:in `parse_file'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/server.rb:162:in `app'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/server.rb:253:in `wrapped_app'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.2.3/lib/rack/server.rb:204:in `start'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands/server.rb:65:in `start'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:30:in `block in <top (required)>'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:27:in `tap'
from /home/app/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:27:in `<top (required)>'
from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:58:in `require'
from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:58:in `rescue in require'
from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'

由于

10 个答案:

答案 0 :(得分:15)

检查你的config / application.rb,你需要添加require'depaise',你应该没问题。

答案 1 :(得分:15)

如果您正在编写具有自己的设备配置的引擎,只需添加

即可
require 'devise'

在设计初始化器的开头。 在我的情况下,我在申请中没有设计要求:)

干杯

答案 2 :(得分:4)

确保您已在Gemfile中列出了Devise并运行bundle install

答案 3 :(得分:3)

当我有一个自定义设计控制器来覆盖'new'方法来做一些自定义的东西时,我得到了一个错误,并且忘了使用'super'

你有自定义控制器吗?

答案 4 :(得分:2)

我有类似的问题,我发现了这个https://github.com/plataformatec/devise

它说你必须做

rails generate devise:install

在该页面上的“入门”后,我开始了

答案 5 :(得分:1)

如果您不再使用devise gem,请删除

gem 'devise'

来自gemfile并删除

config/initializers/devise.rb 

还要确保设备没有在任何地方使用

答案 6 :(得分:1)

我刚才遇到了这个问题,那是因为我错误地生成了一个视图模型而且我没有从我的routes中删除它.rb

答案 7 :(得分:1)

我必须在spec / spec_helper.rb文件中添加require 'devise',并且该错误消失了。

答案 8 :(得分:0)

我在安装Devise后添加了几列,并在我的用户模型中添加了一些验证。 从错误消息,它看起来像铁路找不到必要的库因此它找不到Devise。也许签出Github设计Wiki页面并确保所有依赖项都满意?

希望它有所帮助!

答案 9 :(得分:0)

在您的config / application.rb中添加require 'yaml'。这个对我有用。尝试