有人可以帮我安装 Devise 吗?

Can someone help me with installing Devise?

我已将 gem 'devise' 添加到我的 Gemfile 中。一切都安装正常,但是当我 运行 rails 生成 devise:install 时,我收到此错误。

jshuadvd:estuk joshuadavid$ bundle show devise
/Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1
jshuadvd:estuk joshuadavid$ rails generate devise:install
/Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.1/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined method `devise' for Install (call 'Install.connection' to establish a connection):Class (NoMethodError)
    from /Users/joshuadavid/stukwork/estuk/app/models/install.rb:4:in `<class:Install>'
    from /Users/joshuadavid/stukwork/estuk/app/models/install.rb:1:in `<top (required)>'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:443:in `load'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:443:in `block in load_file'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:633:in `new_constants_in'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:442:in `load_file'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:342:in `require_or_load'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:480:in `load_missing_constant'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:180:in `const_missing'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/inflector/methods.rb:238:in `const_get'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/inflector/methods.rb:238:in `block in constantize'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/inflector/methods.rb:236:in `each'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/inflector/methods.rb:236:in `inject'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/inflector/methods.rb:236:in `constantize'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:552:in `get'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:583:in `constantize'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise.rb:302:in `get'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/mapping.rb:80:in `to'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/mapping.rb:75:in `modules'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/mapping.rb:92:in `routes'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/mapping.rb:159:in `default_used_route'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/mapping.rb:69:in `initialize'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise.rb:336:in `new'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise.rb:336:in `add_mapping'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/rails/routes.rb:224:in `block in devise_for'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/rails/routes.rb:223:in `each'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/devise-3.4.1/lib/devise/rails/routes.rb:223:in `devise_for'
    from /Users/joshuadavid/stukwork/estuk/config/routes.rb:2:in `block in <top (required)>'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_dispatch/routing/route_set.rb:335:in `instance_exec'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_dispatch/routing/route_set.rb:335:in `eval_block'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.1/lib/action_dispatch/routing/route_set.rb:313:in `draw'
    from /Users/joshuadavid/stukwork/estuk/config/routes.rb:1:in `<top (required)>'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `block in load'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/application/routes_reloader.rb:40:in `each'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/application/routes_reloader.rb:26:in `block in updater'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/file_update_checker.rb:75:in `call'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/file_update_checker.rb:75:in `execute'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/application/routes_reloader.rb:27:in `updater'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/application/finisher.rb:71:in `block in <module:Finisher>'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/initializable.rb:30:in `run'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/joshuadavid/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
    from /Users/joshuadavid/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /Users/joshuadavid/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
    from /Users/joshuadavid/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /Users/joshuadavid/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each'
    from /Users/joshuadavid/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `call'
    from /Users/joshuadavid/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
    from /Users/joshuadavid/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
    from /Users/joshuadavid/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/railties-4.1.1/lib/rails/application.rb:288:in `initialize!'
    from /Users/joshuadavid/stukwork/estuk/config/environment.rb:5:in `<top (required)>'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `block in require'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/spring-1.3.3/lib/spring/application.rb:92:in `preload'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/spring-1.3.3/lib/spring/application.rb:143:in `serve'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/spring-1.3.3/lib/spring/application.rb:131:in `block in run'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/spring-1.3.3/lib/spring/application.rb:125:in `loop'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/spring-1.3.3/lib/spring/application.rb:125:in `run'
    from /Users/joshuadavid/.rvm/gems/ruby-2.1.2/gems/spring-1.3.3/lib/spring/application/boot.rb:18:in `<top (required)>'
    from /Users/joshuadavid/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/joshuadavid/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'
jshuadvd:estuk joshuadavid$ 

这是我的 config/application.rb 供审核

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module Estuk
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de
  end
end

如果您还需要什么,请随时提出。谢谢!

为了确保这个问题得到完整回答,您可以在几行中添加几行代码。

首先,您使用

安装设计

gem 'devise' 到你自己的 Gemfile 和 运行 bundle update.

然后,使用

完成安装

rails g devise:install

最后,将 Devise 添加到 config/application.rb:

...
require 'Devise'
require 'rails/all'
...

这应该适用于您的项目。我希望你在 Rails 上玩得开心。祝福。

好的,我成功地重现了这个问题。 He 运行 rails generate devise install 没有冒号。它为 'Install' 生成了模型和路由条目。您可以在堆栈跟踪中看到正在使用的模型。

要解决此问题,请删除此文件:/Users/joshuadavid/stukwork/estuk/app/models/install.rb

然后打开您的路线 (config/routes.rb) 并删除顶部显示 'devise_for Install' 的行。再次保存文件和 运行 安装生成器,这次确保使用正确的版本:rails generate devise:install