5

我正在尝试按照这些说明向 Google 添加 oauth2 。

我在启动服务器时收到以下错误消息:

Exiting
You've tried to invoke Spring when it's already loaded (i.e. the Spring constant is defined).

This is probably because you generated binstubs with Spring 1.0, and you now have a Spring version > 1.0 on your system. To solve this, upgrade your bundle to the latest Spring version and then run `bundle exec spring binstub --all` to regenerate your binstubs. This is a one-time step necessary to upgrade from 1.0 to 1.1.

Here's the backtrace:

/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:287:in `load'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:287:in `block in load'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:287:in `load'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `<top (required)>'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in `require'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in `rescue in require'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
/Users/omonia/Dropbox/MyApp/bin/spring:13:in `<top (required)>'

安装的相关宝石:

gem 'google-api-client', '0.9'
gem 'omniauth'
gem 'omniauth-google_oauth2'

以下代码添加到config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google_oauth2, 'my Google client id', 'my Google client secret', {client_options: {ssl: {ca_file: Rails.root.join("cacert.pem").to_s}}}
end

这里发生了什么?遵循错误说明不会改变任何东西(Spring 是最新版本 1.7.2 并且运行bundle exec spring binstub --all仅返回“spring 已经存在”)。

4

6 回答 6

3

将我的评论作为答案,因为 OP 确认它确实对他有帮助。按照以下步骤安装新的 Spring 并解决问题:

  • 运行这个bin/spring binstub --remove --all
  • 从 Gemfile 中删除 gem 并运行bundle install.
  • 现在gem "spring", group: :development在 Gemfile 中添加,运行bundle installbundle exec spring binstub --all关注doc。现在一切都应该好了。
于 2016-07-29T20:23:03.553 回答
2

在将代码升级到新的 rails 版本后,我遇到了类似的问题,以下评论帮助我解决了这个问题:

https://github.com/rails/spring/issues/610#issuecomment-578188439

基本上,在bin/railsstub 中禁用 spring 加载器,然后运行rails s直到找到并修复所有代码问题,最后启用 spring back。

于 2020-02-25T04:12:15.717 回答
0

这对我有用 -

我在控制台上运行了这个 -rake rails:update:bin

然后我跑了bundle exec spring binstub --all

我不保证这对所有人都有效。

谢谢 :)

于 2017-10-17T14:54:56.173 回答
0

我遇到了类似的问题,在将我的 ruby​​ 版本从 2.6.1 升级到 2.7.1 并将 rails 5 升级到 rails 6 之后。

我在这里阅读了讨论,然后在bin/rails中 禁用了我的加载弹簧代码

#!/usr/bin/env ruby
begin
  load File.expand_path('../spring', __FILE__)
rescue LoadError => e
  raise unless e.message.include?('spring')
end
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'

至:

#!/usr/bin/env ruby
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'

我得到了错误

/home/humayun/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' : 无法加载此类文件 -- thwait (LoadError)

我通过将以下 gem 添加到我的 gem 文件来解决此问题。

gem 'cmath'
gem 'scanf'
gem 'shell'
gem 'sync'
gem 'thwait'
gem 'e2mmap'

此后,我的 rails 工作正常,我将bin/rails移至其原始代码。

于 2021-04-10T20:11:18.410 回答
0

检查config/initializers/omniauth.rb文件并确保您具有以下内容:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google, 'Client_Id', 'Client_Secret'
end

确保您确实拥有 google 提供程序(不是 github 或 facebook)

于 2017-02-10T16:16:50.817 回答
0

首先,我不是 Ruby On Rails 专家,如果我在以下步骤中做错了什么,请纠正我。

对我有用的步骤如下,

从 MacOS 终端运行以下..

bin/spring binstub --remove --all

** 删除 Vender 下的 Your Cache 文件夹(使用 Finder)

捆绑安装。

轨道资产:预编译

于 2020-04-29T07:50:07.850 回答