1

我刚开始学习如何编程,但使用 Ubuntu 已经有几年了,所以我对研究问题和错误非常熟悉,但要么这个领域对我来说太新,要么我真的找不到任何具体的答案。

我正在参加 ruby​​ on rails 介绍课程,到了必须安装设计 gem 的地步,这就是我犯错误的地方。

在按照设计 github 页面上的说明操作时,我不小心输入了:

rails generate devise install

代替

rails generate devise:install

现在,每当我尝试加载

导轨

我收到此错误消息:

/home/amer/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/inflector/methods.rb:230:in `block in constantize': uninitialized constant Install (NameError)
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/inflector/methods.rb:229:in `each'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/inflector/methods.rb:229:in `constantize'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise.rb:256:in `get'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise/mapping.rb:77:in `to'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise/mapping.rb:72:in `modules'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise/mapping.rb:89:in `routes'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise/mapping.rb:156:in `default_used_route'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise/mapping.rb:66:in `initialize'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise.rb:290:in `new'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise.rb:290:in `add_mapping'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise/rails/routes.rb:208:in `block in devise_for'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise/rails/routes.rb:207:in `each'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/devise-2.1.2/lib/devise/rails/routes.rb:207:in `devise_for'
from /home/amer/Documents/Rails_Projects/omrails/omrails1/config/routes.rb:3:in `block in <top (required)>'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/routing/route_set.rb:282:in `eval_block'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/routing/route_set.rb:260:in `draw'
from /home/amer/Documents/Rails_Projects/omrails/omrails1/config/routes.rb:1:in `<top (required)>'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:40:in `each'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:40:in `load_paths'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:16:in `reload!'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:26:in `block in updater'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/file_update_checker.rb:78:in `call'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.9/lib/active_support/file_update_checker.rb:78:in `execute'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:27:in `updater'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application/finisher.rb:66:in `block in <module:Finisher>'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `instance_exec'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `run'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `each'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `run_initializers'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/application.rb:136:in `initialize!'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/amer/Documents/Rails_Projects/omrails/omrails1/config/environment.rb:5:in `<top (required)>'
from /home/amer/Documents/Rails_Projects/omrails/omrails1/config.ru:4:in `block in <main>'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
from /home/amer/Documents/Rails_Projects/omrails/omrails1/config.ru:1:in `new'
from /home/amer/Documents/Rails_Projects/omrails/omrails1/config.ru:1:in `<main>'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/commands/server.rb:46:in `app'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/commands/server.rb:70:in `start'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/commands.rb:55:in `block in <top (required)>'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/commands.rb:50:in `tap'
from /home/amer/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

在此处发布之前,我尝试重新安装 ruby​​ 1.9.3。使用 rvm。我尝试使用

rvm gemset empty [gemset_name]

正如RVM 中所述:卸载 gemset 的所有 gem,但这也没有真正的帮助。

我该怎么办?谁能向我解释这里发生了什么?

4

2 回答 2

1

我理解你的问题。你已经写了rails generate devise install。这意味着您已将其关联install为模型来设计而不是配置它。因此,您的文件是在没有设计配置的情况下创建的。

你只需按照我写的: 1)在'/config/initializers'
中 创建一个devise.rb文件 2)在其中编写以下代码:

Devise.setup do |config|
  config.mailer_sender = "devise@example.com"
  config.scoped_views = true
  require 'devise/orm/active_record'#[这对你有用]
  config.case_insensitive_keys = [ :email ]
  config.strip_whitespace_keys = [ :email ]
  config.skip_session_storage = [:http_auth]
  config.stretches = Rails.env.test? ? 1 : 10
  config.reconfirmable = true
  config.reset_password_within = 6.hours
  config.sign_out_via = :delete
end

rails destroy devise install2)并在终端中写入。就是这样。
我认为以上肯定会奏效。

3)现在再次启动您的服务器rails s
4) 再次小心安装设备。然后继续。

于 2012-12-04T04:40:54.417 回答
0

我认为您没有 gem 问题,只是混淆了 Devise 设置,这很可能很容易混淆。

当您运行 Devise 生成器(带有rails generate Devise:something)时,它会运行代码以在您的应用程序树 (app/*) 中创建一些特定于您的应用程序的文件。我正在查看一个设计安装,并认为它主要位于app/views/devise目录中,但它也有可能更新您的用户模型。它肯定会更新您的app/routes.rb文件并在config/initializers. 可能还有其他人。

删除其中任何一个。语言环境中可能还有其他文件,db/migrate(有一个迁移——不要运行它,或者rake db:rollback如果有的话,在删除它之前运行)。

然后重新运行安装。

如果这不起作用,另一种方法是创建一个新的虚拟 Rails 应用程序,在那里安装设计,然后查看创建了哪些文件——通常生成器会报告它们在做什么。

于 2012-12-04T01:07:32.487 回答