0

嘿,我是 Rails 新手,每当我尝试运行时都会收到此错误

rails generate devise User

我在终端收到此错误:

/usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/application/routes_reloader.rb:10:in `rescue in execute_if_updated': Rails::Application::RoutesReloader#execute_if_updated delegated to updater.execute_if_updated, but updater is nil: #<Rails::Application::RoutesReloader:0x007fcad64c5e20 @paths=["/Users/DavidStevenson/Desktop/omrails/omrails/config/routes.rb"], @route_sets=[#<ActionDispatch::Routing::RouteSet:0x007fcad64c5d80>]> (RuntimeError)
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/initializable.rb:30:in `instance_exec'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/initializable.rb:30:in `run'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tsort.rb:150:in `block in tsort_each'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tsort.rb:219:in `each_strongly_connected_component_from'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tsort.rb:182:in `block in each_strongly_connected_component'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tsort.rb:180:in `each'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tsort.rb:180:in `each_strongly_connected_component'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/tsort.rb:148:in `tsort_each'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/initializable.rb:54:in `run_initializers'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/application.rb:215:in `initialize!'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/DavidStevenson/Desktop/omrails/omrails/config/environment.rb:5:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:228:in `require'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:228:in `block in require'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:213:in `load_dependency'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:228:in `require'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/application.rb:189:in `require_environment!'
    from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-4.0.0.rc2/lib/rails/commands.rb:47:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

我查看了 routes.rb 文件,没有发现任何明显错误。当我注释掉这一行时:

devise_for :installs

我可以再次运行服务器。任何想法为什么会发生这种情况?

4

2 回答 2

1

首先,你为什么使用 ruby​​ 1.9.3 而不是 2.0 ?其次,为什么你使用 rails 4.0.0.rc2 而不是它的稳定版本 4.0 ?

对于你的问题,

devise_for :users在您的 routes.rb 文件中设计需要。它必须与您的资源名称相同。user在 routes.rb 和你的生成器中都使用。

于 2013-08-10T19:54:49.277 回答
1

我从 Active Record 迁移到 MongoID 后发现了这个错误,问题是 Devise 初始化程序 ( config/initializers/devise.rb) 指定了 ORM(对我来说是第 25 行):

require 'devise/orm/active_record'

我只需要将这一行替换为:

require 'devise/orm/mongoid'

现在正在工作:)

于 2014-04-17T12:09:12.740 回答