【问题标题】:Can't install Devise无法安装设计
【发布时间】:2014-09-13 10:10:25
【问题描述】:

尝试安装 Devise,我收到以下消息“找不到生成器 devise:install。”

leigh@leigh-VirtualBox:~/Projects/dev01$ bundle install
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.4
Using builder 3.2.2
Using erubis 2.7.0
Using actionview 4.1.4
Using rack 1.5.2
Using rack-test 0.6.2
Using actionpack 4.1.4
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.4
Using activemodel 4.1.4
Using arel 5.0.1.20140414130214
Using activerecord 4.1.4
Using execjs 2.2.1
Using autoprefixer-rails 2.1.1.20140710
Using bcrypt 3.1.7
Using sass 3.2.19
Using bootstrap-sass 3.2.0.0
Using thor 0.19.1
Using railties 4.1.4
Using bootswatch-rails 3.2.0
Using coffee-script-source 1.7.1
Using coffee-script 2.3.0
Using coffee-rails 4.0.1
Using data-confirm-modal 1.0.1 from git://github.com/ifad/data-confirm-modal.git (at master)
Using declarative_authorization 0.5.7
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.3
Using jquery-rails 3.1.1
Using bundler 1.6.4
Using tilt 1.4.1
Using sprockets 2.11.0
Using sprockets-rails 2.1.3
Using rails 4.1.4
Using rdoc 4.1.1
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.3
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
leigh@leigh-VirtualBox:~/Projects/dev01$ rails generate devise:install
Could not find generator devise:install.
leigh@leigh-VirtualBox:~/Projects/dev01$ 

我的 Gemfile 是:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.4'
# 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

gem 'bootstrap-sass', '~> 3.2.0.0'
gem 'bootswatch-rails', '~> 3.2.0'

gem 'autoprefixer-rails'

# Use data-confirm-modal to create custom alert modal popups
gem 'data-confirm-modal', github: 'ifad/data-confirm-modal'

# Use devise for user authentication
gem 'devise'
# Use declarative_authorization for user authorisation
gem 'declarative_authorization'

# 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]

Rails 版本是:

leigh@leigh-VirtualBox:~/Projects/dev01$ rails -v
Rails 4.1.4
leigh@leigh-VirtualBox:~/Projects/dev01$ 

操作系统版本是:

leigh@leigh-VirtualBox:~/Projects/dev01$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04 LTS
Release:    14.04
Codename:   trusty
leigh@leigh-VirtualBox:~/Projects/dev01$ 

关于为什么将 Devise gem 正确添加到 Gemfile 并运行捆绑安装后无法安装的任何想法?

我确实在某个时间点运行了服务器(rails 服务器),并看到一篇文章指出尝试在服务器启动时安装 Devise 可能会导致奇怪的问题。

此后我再次尝试关闭服务器,但没有任何区别。我确定这可能是因为我在设置中忽略了一些非常简单的事情,只是不确定还有什么地方可以看。

任何关于下一步看哪里的建议或建议都会很棒,谢谢。

我已经使用以下命令完成了测试,但仍然收到相同的错误:

leigh@leigh-VirtualBox:~/Projects/dev01$ bundle exec rails g devise:install
Could not find generator devise:install.

已安装的生成器列表如下,而 Devise 未列出,我如何将其列出?

leigh@leigh-VirtualBox:~/Projects/dev01$ rails generate
Usage: rails generate GENERATOR [args] [options]

General options:
  -h, [--help]     # Print generator's options and usage
  -p, [--pretend]  # Run but do not make any changes
  -f, [--force]    # Overwrite files that already exist
  -s, [--skip]     # Skip files that already exist
  -q, [--quiet]    # Suppress status output

Please choose a generator below.

Rails:
  assets
  controller
  generator
  helper
  integration_test
  jbuilder
  mailer
  migration
  model
  resource
  scaffold
  scaffold_controller
  task

Coffee:
  coffee:assets

Jquery:
  jquery:install

Js:
  js:assets

TestUnit:
  test_unit:generator
  test_unit:plugin

leigh@leigh-VirtualBox:~/Projects/dev01$

【问题讨论】:

  • 如果您输入rails generate,您会在任何地方看到设计选项吗?
  • 您使用的是 RVM 还是任何其他版本管理器。您可能将 Devise gem 安装在与您预期不同的 gemset 上。
  • 不,运行 rails generate 没有列出设计
  • 我正在使用 rbenv 进行版本控制/管理。

标签: ruby-on-rails ruby devise


【解决方案1】:

今天同样的问题,我从 Gemfile 中删除了“弹簧”,它成功了。 或者您可以先关闭弹簧并运行 rails generate devise:install

【讨论】:

  • 并在删除“弹簧”后运行 rails generate devise:install 我应该把它加回去吗?实际上移除“弹簧”对我不起作用
【解决方案2】:

好的,我仍然不能 100% 确定为什么会这样,或者首先是什么导致了问题,但是在运行以下命令之后:

leigh@leigh-VirtualBox:~/Projects/dev01$ gem uninstall devise
Successfully uninstalled devise-3.2.4
leigh@leigh-VirtualBox:~/Projects/dev01$ gem uninstall warden
Successfully uninstalled warden-1.2.3
leigh@leigh-VirtualBox:~/Projects/dev01$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching additional metadata from https://rubygems.org/..
[... text removed ...]
Installing warden 1.2.3
Installing devise 3.2.4
[... text removed ...]
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
leigh@leigh-VirtualBox:~/Projects/dev01$ rails generate devise:install
      create  config/initializers/devise.rb
      create  config/locales/devise.en.yml

呜呼!!!问题解决了。浪费几天的好方法:-(

【讨论】:

    【解决方案3】:

    对我有用的是:

    $ sudo -s
    $ bundle exec rails generate devise:install
    

    没有 sudo 或运行“初始化程序”/bin/bash --login 不起作用。另一个解决方案可能是删除 Gemfile.lock 并再次运行 bundle install

    【讨论】:

      【解决方案4】:

      这似乎在我的 RVM 下的机器上工作,但这是使用新的 gemset。如果您使用与其他 Rails 安装共享的 Ruby 版本(或 RVM gemset),您可能会遇到问题。

      当您使用 Bundler 时,您可能应该使用:

      bundle exec rails g devise:install
      

      作为一般预防措施,以确保您使用的是捆绑包的宝石。

      【讨论】:

      • 嗨@AFaderDarkly,我已经尝试过这个命令,并用结果更新了我上面的原始帖子。
      • 我从其他 cmets 看到您正在使用 rbenv。我是 rvm 用户,不幸的是我没有任何 rbenv 经验。但是,要查看的一件事可能是您正在使用的“rails”命令的位置以及您正在使用的 ruby​​ 版本的 ruby​​ gem 的位置。如果它们不匹配,则来自另一个 ruby​​ 版本的 rails 命令可能会覆盖您想要的那个。要检查的另一件事(查看 rbenv 文档)是确保 ~/.rbenv/shims 位于路径的开头。 (如果您使用的是带有 bash shell 的 Linux 或 OSX,请查看 ~/.bashrc 或 ~/.bash_profile。)
      • 感谢 Fader,检查了以下内容,两条路径都匹配,我更改了我的 PATH,以便 shims 路径在开始但仍然没有乐趣:-( leigh@leigh-VirtualBox:~/Projects/dev01 $ rbenv --version rbenv 0.4.0-98-g13a474c leigh@leigh-VirtualBox:~/Projects/dev01$ which rails /home/leigh/.rbenv/shims/rails leigh@leigh-VirtualBox:~/Projects/dev01$哪个红宝石/home/leigh/.rbenv/shims/ruby
      • leigh@leigh-VirtualBox:~/Projects/dev01$ echo $PATH /home/leigh/.rbenv/shims:/home/leigh/.rbenv/plugins/ruby-build/bin:/ home/leigh/.rbenv/bin:/home/leigh/.rbenv/shims:/home/leigh/.rbenv/plugins/ruby-build/bin:/home/leigh/.rbenv/bin:/home/leigh/ .rbenv/shims:/home/leigh/.rbenv/plugins/ruby-build/bin:/home/leigh/.rbenv/shims:/home/leigh/.rbenv/bin:/usr/local/sbin:/usr /local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games leigh@leigh-VirtualBox:~/Projects/dev01$
      • 我的想法已经不多了。 :(您是否尝试过使用相同的 ruby​​ 版本和新安装的 Rails 和安装了 only 设计的 Gemfile?如果这有效(就像对我一样)然后尝试添加其他 gem 依赖项,直到它休息。
      【解决方案5】:

      我通过将以下行添加到我的Gemfile 来修复它:

      gem 'devise' 
      

      添加那行之后,我执行了bundle install

      【讨论】:

        【解决方案6】:

        我今天也遇到了同样的问题。我尝试卸载 devisewarden 但没有运气。最后我删除了Gemfile.lock 并再次运行bundle install 就成功了。

        【讨论】:

          【解决方案7】:

          这听起来很荒谬,但请打开一个新的终端窗口并重试。这就是它最终对我来说。如果还是不行,试试:

          DISABLE_SPRING=1 bundle exec rails g devise:install

          【讨论】:

            【解决方案8】:

            我今天在vscode终端也遇到了同样的问题,尝试删除gemfile.lock,如果不起作用,重复以下过程。

            您可以删除 de gemfile,然后在新终端上尝试捆绑安装。

            我认为这是 vscode 的权限问题。

            在第一步中,您可以删除 gemfile 上的设计行并再次手动添加 -> gemfile 'devise'

            步骤:

            • 1.0 在您的终端上试用。
            • 1.1 删除 gemfile.lock。
            • 1.2 运行捆绑安装。
            • 1.3 运行 rails g devise:install。

            如果不行

            • 2.0 退出终端 e 打开一个新的。
            • 2.1 尝试在 1.1 到 1.3 上运行相同的步骤

            给我解决了。

            【讨论】:

              【解决方案9】:

              就我而言,我使用的是:

              gem 'rack-cors', :require 'rack-cors'
              

              然后我得到了同样的错误,但这里的解决方案都没有解决它。

              我不得不更换它只是为了像这样:

              gem 'rack-cors'
              

              然后运行

              $ 捆绑安装

              $ rails generate devise:install

              【讨论】:

                【解决方案10】:

                我关闭终端并打开一个新终端。 然后 rails 生成 devise:install

                这次成功了。太诡异了!

                【讨论】:

                  【解决方案11】:

                  重新启动控制台将解决此问题。

                  【讨论】:

                    猜你喜欢
                    • 1970-01-01
                    • 1970-01-01
                    • 2014-06-01
                    • 2011-05-08
                    • 1970-01-01
                    • 1970-01-01
                    • 2014-08-12
                    • 2016-09-26
                    • 2016-06-13
                    相关资源
                    最近更新 更多