有人可以帮我安装Devise吗?

时间:2015-02-27 23:36:29

标签: ruby-on-rails ruby devise gem

我已将gem'devise'添加到我的Gemfile中。一切安装都很好,但是当我运行rails generate 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

如果您还有其他需求,请随时提出。谢谢!

2 个答案:

答案 0 :(得分:2)

好的,我设法重现了这个问题。他没有结肠跑rails generate devise install。这为“安装”生成了模型和路径条目。您可以在堆栈跟踪中看到正在使用的模型。

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

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

答案 1 :(得分:0)

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

首先,使用

安装设备

gem 'devise'到您自己的Gemfile中并运行bundle update

然后,用

完成安装

rails g devise:install

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

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

这应该可以成功地与您的项目一起使用。我希望你在使用Rails时获得很多乐趣。祝福。