Ruby-on-rails 为什么在运行 webrick 服务器时出现未初始化的常量设计名称错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6551946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 01:30:45  来源:igfitidea点击:

why do I get uninitialized constant Devise name Error when running webrick server?

ruby-on-railsrubydevise

提问by Addicted

In my application I have used ruby 1.9.2 and rails 3.0.3 and have also installed Devise gem.The problem begins when I run the Webrick server I get uninitialized constant Devise name Error.

在我的应用程序中,我使用了 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'

Thanks

谢谢

回答by Marshall Shen

Check your config/application.rb, you need to add require 'devise' and you should be fine.

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

回答by m4risU

In case you are writing an engine which has its own devise config, just add

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

require 'devise'

on the beginning of devise initializer. In my case I had no devise requirement within application :)

在设计初始值设定项的开始。就我而言,我在应用程序中没有设计要求:)

Cheers

干杯

回答by Luke

Make sure you've listed Devise in your Gemfile and run bundle install.

确保你已经在你的 Gemfile 中列出了 Devise 并运行bundle install.

回答by jpw

I got an error like that when I had a custom devise controller to override the 'new' method to do some custom stuff, and forgot to use 'super'

当我有一个自定义设计控制器来覆盖“新”方法来执行一些自定义操作时,我遇到了这样的错误,而忘记使用“超级”

Do you have a custom controller?

你有自定义控制器吗?

回答by C. Louis S.

I had a similar issue and i found this https://github.com/plataformatec/devise

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

It says you have to do

它说你必须做

rails generate devise:install

rails generate devise:install

Following "Getting Started" on that page got me going

遵循该页面上的“入门”让我继续前进

回答by Muhammad Aqeel

if you are not using devise gem anymore then remove

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

gem 'devise'

from gemfile and delete

从 gemfile 中删除

config/initializers/devise.rb 

also make sure devise is not being used anywhere

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

回答by LiffeyD

I just had that issue, it was because I generated a view model by mistake and I didnt delete it from my routes.rb

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

回答by cam_271

I had to add require 'devise'in the spec/spec_helper.rb file and that error went away.

我不得不require 'devise'在 spec/spec_helper.rb 文件中添加,那个错误就消失了。

回答by Андр?й Душар

In your config/application.rb add require 'yaml'. It works for me. Try

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

回答by Marshall Shen

I added few columns after I install Devise and I added some validations in my user model. From error message, it looks like rails cannot find the essential library therefore it can't find Devise. Maybe checkout the Github devise Wiki page and makes sure all the dependencies are satisfied?

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

Hope it helps!

希望能帮助到你!