Ruby on Rails - 在 OSX 上使用 Ruby 2.4.4 而不是 rails 5.1.6 的配置问题/异常
Posted
技术标签:
【中文标题】Ruby on Rails - 在 OSX 上使用 Ruby 2.4.4 而不是 rails 5.1.6 的配置问题/异常【英文标题】:Ruby on Rails - configuration issue/exception on OSX using Ruby 2.4.4 over rails 5.1.6 【发布时间】:2021-05-06 18:25:36 【问题描述】:配置现有的 ruby on rails 项目遇到一些奇怪的配置问题 - 似乎我缺少一些配置。
我在我的 MAC 机器上执行了以下某些步骤。
配置 Ruby 环境: => rbenv 安装 2.4.4 => rbenv 本地 2.4.4
-
bundle 配置设置路径 ~/.bundle
捆绑安装
npm 安装
bundle exec rails server -b 0.0.0.0 -p 3001
bundle exec rails server -b 0.0.0.0 -p 3001 导致我无法找到原因的严重异常。
退出 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/deprecated-2.0.1/lib/deprecated.rb:176:in `instance_method': :sanitize_conditions=>:sanitize_sql 不是符号也不是字符串(类型错误) 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/deprecated-2.0.1/lib/deprecated.rb:176:in `block in' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/sanitization.rb:32:in `' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/sanitization.rb:5:in `' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/sanitization.rb:2:in `' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/sanitization.rb:1:in `' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `block in require' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:256:in `block in load_dependency' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:662:in `new_constants_in' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:256:in `load_dependency' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/base.rb:297:in `' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/base.rb:275:in `' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/base.rb:25:in `' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `block in require' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:256:in `block in load_dependency' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:662:in `new_constants_in' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:256:in `load_dependency' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require' 来自 /Users/xxxxxx/workspace/my-project/rails/app/models/cloud/entry.rb:2:in `' 来自 /Users/xxxxxx/workspace/my-project/rails/app/models/cloud/entry.rb:1:in `' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:477:in `load' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:477:in `block in load_file' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:662:in `new_constants_in' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:476:in `load_file' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:374:in `block in require_or_load' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:36:in `block in load_interlock' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies/interlock.rb:12:in `block in loading' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/concurrency/share_lock.rb:149:in `exclusive' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies/interlock.rb:11:in `loading' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:36:in `load_interlock' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:357:in `require_or_load' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:511:in `load_missing_constant' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:202:in `const_missing' 来自 /Users/xxxxxx/workspace/my-project/rails/test/factories/cloud/entries.rb:2:in `block in ' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/factory_bot-4.10.0/lib/factory_bot/syntax/default.rb:49:in `instance_eval' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/factory_bot-4.10.0/lib/factory_bot/syntax/default.rb:49:in `run' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/factory_bot-4.10.0/lib/factory_bot/syntax/default.rb:7:in `define' 来自 /Users/xxxxxx/workspace/my-project/rails/test/factories/cloud/entries.rb:1:in `' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:286:in `load' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:286:in `block in load' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:258:in `load_dependency' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:286:in `load' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/factory_bot-4.10.0/lib/factory_bot/find_definitions.rb:20:in `block (2 levels) in find_definitions' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/factory_bot-4.10.0/lib/factory_bot/find_definitions.rb:19:in `each' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/factory_bot-4.10.0/lib/factory_bot/find_definitions.rb:19:in `block in find_definitions' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/factory_bot-4.10.0/lib/factory_bot/find_definitions.rb:15:in `each' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/factory_bot-4.10.0/lib/factory_bot/find_definitions.rb:15:in `find_definitions' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/factory_bot_rails-4.10.0/lib/factory_bot_rails/railtie.rb:21:in `block in' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:67:in `block in execute_hook' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:60:in `with_execution_control' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:65:in `execute_hook' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:50:in `block in run_load_hooks' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:49:in `each' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:49:in `run_load_hooks' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/application/finisher.rb:73:in `block in' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `instance_exec' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `run' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:59:in `block in run_initializers' 来自 /Users/xxxxxx/.rbenv/versions/2.4.4/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each' 来自 /Users/xxxxxx/.rbenv/versions/2.4.4/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component' 来自 /Users/xxxxxx/.rbenv/versions/2.4.4/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from' 来自 /Users/xxxxxx/.rbenv/versions/2.4.4/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component' 来自 /Users/xxxxxx/.rbenv/versions/2.4.4/lib/ruby/2.4.0/tsort.rb:347:in `each' 来自 /Users/xxxxxx/.rbenv/versions/2.4.4/lib/ruby/2.4.0/tsort.rb:347:in `call' 来自 /Users/xxxxxx/.rbenv/versions/2.4.4/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component' 来自 /Users/xxxxxx/.rbenv/versions/2.4.4/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each' 来自 /Users/xxxxxx/.rbenv/versions/2.4.4/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:58:in `run_initializers' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/application.rb:353:in `initialize!' 来自 /Users/xxxxxx/workspace/my-project/rails/config/environment.rb:5:in `' 来自 config.ru:3:in `require' 来自 config.ru:3:in `block in ' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/rack-2.0.7/lib/rack/builder.rb:55:in `instance_eval' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/rack-2.0.7/lib/rack/builder.rb:55:in `initialize' 来自 config.ru:in `new' 来自 config.ru:in `' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/rack-2.0.7/lib/rack/builder.rb:49:in `eval' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/rack-2.0.7/lib/rack/builder.rb:49:in `new_from_string' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/rack-2.0.7/lib/rack/builder.rb:40:in `parse_file' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/rack-2.0.7/lib/rack/server.rb:319:in `build_app_and_options_from_config' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/rack-2.0.7/lib/rack/server.rb:219:in `app' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:24:in `app' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/rack-2.0.7/lib/rack/server.rb:354:in `wrapped_app' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:80:in `log_to_stdout' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:42:in `start' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:135:in `block in perform' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:130:in `tap' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:130:in `perform' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/command/base.rb:63:in `perform' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/command.rb:44:in `invoke' 来自 /Users/xxxxxx/.bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands.rb:16:in `' 从 bin/rails:4:in `require' 从 bin/rails:4:in `'【问题讨论】:
错误信息显示问题出在app/models/cloud/entry.rb
的第 2 行。那里有什么?
我不确定上面提到的deprecated
gem 是什么,但如果是this,请注意这个版本是2009 年发布的; long 早于 ruby 2.4 存在。可能因为您尝试在比以前更新的 ruby 版本上运行项目而发生此错误?
app/models/cloud/entry.rb的起始行是>>>>>模块云类Entry<:base>
我猜你必须更改了 something 的版本,这样做会引入这个冲突,但我不确定是什么那个变化是。我最好的猜测是ActiveRecord
的版本已经更新,因为that change 是在早期版本的rails 上引入的。
尝试在Gemfile.lock
中通过关键字depecated
搜索使用gem deprecated
的人,然后从Gemfile
中删除gem。 rails 中不应该有 gem deprecated
【参考方案1】:
需要通过执行命令 bundle remove $DEPRECATED_GEMS 来删除/升级在我的 Gemfile.lock 中有 deprecated 关键字的 gem。
在我的情况下,很少有已弃用的宝石,例如, dbd_odbc、ruby_odbc
最初@itsnikolay 为我的问题提供了这个解决方案。
【讨论】:
以上是关于Ruby on Rails - 在 OSX 上使用 Ruby 2.4.4 而不是 rails 5.1.6 的配置问题/异常的主要内容,如果未能解决你的问题,请参考以下文章
让 wkhtmltoimage 在 Amazon Linux / Ruby on Rails 上工作的问题
rails 服务器无法在 OSX 10.6.5 上使用 rvm 和 ruby 1.9.2-p0 启动 mysql2
在 Ruby on Rails 上使用 javascript 注入 ruby
如何在我的 Ruby on Rails 应用程序上使用 ruby 2.7