Rails 4和Devise(NoMethoderror)

时间:2014-07-15 08:48:56

标签: ruby-on-rails ruby ruby-on-rails-4 devise gem

我正在学习如何使用rails gem在ruby上构建Web应用程序。 遵循本教程:http://12devs.co.uk/articles/writing-a-web-application-with-ruby-on-rails/

一切都很好&在我开始为用户身份验证功能安装Devise gem之前清除。

我在执行rails generate devise:install

后收到错误消息

错误报告就是这个史诗(看起来我以某种方式搞砸了一些依赖):

sergey@sergey-VirtualBox:~/Bookmarks$ rails generate devise:install
/home/sergey/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.0/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 /home/sergey/Bookmarks/app/models/install.rb:4:in `<class:Install>'
    from /home/sergey/Bookmarks/app/models/install.rb:1:in `<top (required)>'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:443:in `load'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:443:in `block in load_file'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:633:in `new_constants_in'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:442:in `load_file'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:342:in `require_or_load'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:480:in `load_missing_constant'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:180:in `const_missing'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/inflector/methods.rb:238:in `const_get'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/inflector/methods.rb:238:in `block in constantize'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/inflector/methods.rb:236:in `each'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/inflector/methods.rb:236:in `inject'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/inflector/methods.rb:236:in `constantize'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:552:in `get'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:583:in `constantize'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/devise-3.2.4/lib/devise.rb:297:in `get'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/devise-3.2.4/lib/devise/mapping.rb:77:in `to'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/devise-3.2.4/lib/devise/mapping.rb:72:in `modules'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/devise-3.2.4/lib/devise/mapping.rb:89:in `routes'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/devise-3.2.4/lib/devise/mapping.rb:156:in `default_used_route'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/devise-3.2.4/lib/devise/mapping.rb:66:in `initialize'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/devise-3.2.4/lib/devise.rb:331:in `new'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/devise-3.2.4/lib/devise.rb:331:in `add_mapping'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/devise-3.2.4/lib/devise/rails/routes.rb:221:in `block in devise_for'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/devise-3.2.4/lib/devise/rails/routes.rb:220:in `each'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/devise-3.2.4/lib/devise/rails/routes.rb:220:in `devise_for'
    from /home/sergey/Bookmarks/config/routes.rb:2:in `block in <top (required)>'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.0/lib/action_dispatch/routing/route_set.rb:335:in `instance_exec'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.0/lib/action_dispatch/routing/route_set.rb:335:in `eval_block'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.0/lib/action_dispatch/routing/route_set.rb:313:in `draw'
    from /home/sergey/Bookmarks/config/routes.rb:1:in `<top (required)>'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `block in load'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/application/routes_reloader.rb:40:in `each'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/application/routes_reloader.rb:26:in `block in updater'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/file_update_checker.rb:75:in `call'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/file_update_checker.rb:75:in `execute'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/application/routes_reloader.rb:27:in `updater'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/application/finisher.rb:71:in `block in <module:Finisher>'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/initializable.rb:30:in `run'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/sergey/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
    from /home/sergey/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /home/sergey/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
    from /home/sergey/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /home/sergey/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each'
    from /home/sergey/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `call'
    from /home/sergey/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
    from /home/sergey/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
    from /home/sergey/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/application.rb:288:in `initialize!'
    from /home/sergey/Bookmarks/config/environment.rb:5:in `<top (required)>'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `block in require'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/application.rb:264:in `require_environment!'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:147:in `require_application_and_environment!'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:133:in `generate_or_destroy'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:51:in `generate'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /home/sergey/.rvm/gems/ruby-2.1.2/gems/railties-4.1.0/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

我使用的操作系统是托管在Oracle Virtualbox中的Ubuntu 14。 Virtualbox在Windows 7上运行。 安装的ruby版本是:

sergey@sergey-VirtualBox:~/Bookmarks$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]

项目创建如下:

rails new Bookmarks -T -d sqlite3 -B

Gemfile.rb内容为:

source 'https://rubygems.org'

# Devise gem for User Authorisation
gem 'devise', '~> 3.2.4'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring',        group: :development

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

使用bundler管理宝石。 安装的轨道宝石是:

sergey@sergey-VirtualBox:~/Bookmarks$ bundle update
Fetching gem metadata from https://rubygems.org/..........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Using rake 10.3.2
Using i18n 0.6.11
Using json 1.8.1
Using minitest 5.4.0
Using thread_safe 0.3.4
Using tzinfo 1.2.1
Using activesupport 4.1.0
Using builder 3.2.2
Using erubis 2.7.0
Using actionview 4.1.0
Using rack 1.5.2
Using rack-test 0.6.2
Using actionpack 4.1.0
Using mime-types 1.25.1
Using polyglot 0.3.5
Using treetop 1.4.15
Using mail 2.5.4
Using actionmailer 4.1.0
Using activemodel 4.1.0
Using arel 5.0.1.20140414130214
Using activerecord 4.1.0
Using bcrypt 3.1.7
Using bundler 1.6.2
Using coffee-script-source 1.7.1
Using execjs 2.2.1
Using coffee-script 2.3.0
Using thor 0.19.1
Using railties 4.1.0
Using coffee-rails 4.0.1
Using orm_adapter 0.5.0
Using warden 1.2.3
Using devise 3.2.4
Using hike 1.2.3
Using multi_json 1.10.1
Using jbuilder 2.1.2
Using jquery-rails 3.1.1
Using tilt 1.4.1
Using sprockets 2.11.0
Using sprockets-rails 2.1.3
Using rails 4.1.0
Using rdoc 4.1.1
Using sass 3.2.19
Using sass-rails 4.0.3
Using sdoc 0.4.0
Using spring 1.1.3
Using sqlite3 1.3.9
Using turbolinks 2.2.2
Using uglifier 2.5.1
Your bundle is updated!

我知道这里有一个同样错误的问题(即使版本相似)devise gem install for Ruby on Rails

但没有答复,我试图提供更多信息。

我也试过this回答,没有效果。

你能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

最近我回到了使用devise gem并解决它的问题。 很可能是依赖性问题。

不幸的是我不知道到底出了什么问题,因为我刚刚卸载了所有可能对我的Ruby安装及其gems依赖性产生任何影响并重新安装的所有内容。

首先,我删除了我的试用版应用程序,以便在适当的环境下进一步重新创建它。

然后我按照这个guide来准备干净的Ubuntu for Ruby安装和安装Ruby本身(从删除Ubuntu的旧版rvmruby开始)。

以下guide用于安装rails,但只需gem install rails即可。

要使用新的Ruby on Rails环境重新创建我的试用版应用程序,我仍然关注此guide(与问题相同)。

此时间命令:

rails g devise:install

工作得很好。

此外,我对进一步的指导说明没有任何问题。