繁体   English   中英

Spring和中间件冲突?

[英]Spring and middleware conflict?

我正在尝试按照这些说明使用 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已经存在”)。

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

  • 运行这个bin/spring binstub --remove --all
  • 从 Gemfile 中删除 gem 并运行bundle install
  • 现在在 Gemfile 中添加gem "spring", group: :development development,运行bundle installbundle exec spring binstub --all以下doc 现在一切都应该好了。

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

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

基本上,在bin/rails存根中禁用 spring loader,然后运行rails s直到找到并修复所有代码问题,最后,启用回弹。

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

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

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

这对我有用-

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

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

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

谢谢:)

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

对我有用的步骤如下,

从 MacOS 终端运行以下..

bin/spring binstub --remove --all

** 在 Vender 下删除您的缓存文件夹(使用 Finder)

捆绑安装。

rails 资产:预编译

我有一个类似的问题,在将我的 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移动到其原始代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM