在 Rails 管理中创建新对象在更新后不起作用

Creating new object in Rails Admin not working after updates

我正在用 Ruby 3 和 Rails 6.1 重写我用 Ruby 2.7 和 Rails 6.0 构建的项目。我正在使用 rails admin gem 以及 devise 和 cancancan。在我的旧项目中,创建简单的 EventCategory 对象没有任何问题。当我现在尝试时,我得到:

和:

Started POST "/admin/event_category/new" for ::1 at 2020-12-28 13:44:46 -0500
Processing by RailsAdmin::MainController#new as HTML
  Parameters: {"authenticity_token"=>"[FILTERED]", "event_category"=>{"name"=>"Run", "description"=>"", "unit_of_measurement"=>""}, "return_to"=>"http://localhost:3000/u/sign_in", "_save"=>"", "model_name"=>"event_category"}
  User Load (1.0ms)  SELECT "users".* FROM "users" WHERE "users"."id" =  ORDER BY "users"."id" ASC LIMIT   [["id", 1], ["LIMIT", 1]]
  ↳ config/initializers/rails_admin.rb:7:in `block (2 levels) in <main>'
Completed 500 Internal Server Error in 6ms (ActiveRecord: 1.0ms | Allocations: 2754)


  
ArgumentError (wrong number of arguments (given 1, expected 0)):
  
activerecord (6.1.0) lib/active_record/suppressor.rb:43:in `save'
rails_admin (2.0.2) lib/rails_admin/adapters/active_record/abstract_object.rb:23:in `save'
rails_admin (2.0.2) lib/rails_admin/config/actions/new.rb:41:in `block (2 levels) in <class:New>'
rails_admin (2.0.2) app/controllers/rails_admin/main_controller.rb:22:in `instance_eval'
rails_admin (2.0.2) app/controllers/rails_admin/main_controller.rb:22:in `new'

这是我在 event_category.rb

中的模型
class EventCategory < ApplicationRecord
  has_many :events

  rails_admin do 
    edit do
      field :name
      field :description
      field :unit_of_measurement
    end
  end
end

非常感谢您提供有关这方面的指导。

我的猜测是您可能在 ruby 2.7 中收到弃用警告,现在 returns 您在 ruby 3.0 中看到的错误。 根据 ruby 3.0 changelist,如果要将散列作为参数传递给需要关键字参数的方法,则必须使用双 splat 运算符 (**)。

我不熟悉 RailsAdmin(我通常使用 ActiveAdmin),但是如果您知道一种“拦截”参数并使用 ** 运算符将它们传递给保存方法的方法,它应该可以解决您的问题.