Rails 6、Ruby 3.0.2 中的acts_as_commentable 的替代品是什么?

Dav*_*ave 5 monkeypatching ruby-on-rails acts-as-commentable ruby-on-rails-6 ruby-3

我将我们的应用程序升级到 Rails 6.1.4.4 和 Ruby 3.0.2。我有这颗古老的宝石

\n
gem 'acts_as_commentable'\n
Run Code Online (Sandbox Code Playgroud)\n

锁定在 4.0.2 版本。该 gem 似乎不再受支持,这很遗憾,因为当我启动我的应用程序或控制台时,我现在收到此错误

\n
$ rails c\nYour Gemfile lists the gem rspec-rails (>= 0) more than once.\nYou should probably keep only one of them.\nRemove any duplicate entries and specify the gem only once.\nWhile it's not a problem now, it could cause errors if you change the version of one of them later.\n/Users/myuser/.rvm/gems/ruby-3.0.2/gems/hash_dot-2.5.0/lib/hash.rb:19:in `method_missing': undefined method `arity' for {:as=>:commentable, :dependent=>:destroy}:Hash (NoMethodError)\n    from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:53:in `build_scope'\n    from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:47:in `create_reflection'\n    from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:32:in `build'\n    from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations.rb:1458:in `has_many'\n    from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/acts_as_commentable-4.0.2/lib/commentable_methods.rb:58:in `acts_as_commentable'\n\n    \xe2\x80\xa6\n
Run Code Online (Sandbox Code Playgroud)\n

是否有任何简单的替代品可以替代这个 gem 或者猴子修补这个错误的方法,以便我可以启动该应用程序?

\n

小智 1

查看这些分支,我发现这个分支似乎适合我使用 Rails 6.0.6 和 Ruby 3.0.5。

https://github.com/alazycoder101/acts_as_commentable.git

我还没有对其进行广泛的测试,但至少基本功能似乎对我有用。希望这可以帮助。

为了清楚起见,要使用该分支,您可以在 Gemfile 中使用以下行:

gem 'acts_as_commentable', git: 'https://github.com/alazycoder101/acts_as_commentable.git'
Run Code Online (Sandbox Code Playgroud)