1

I'm rewriting a project that I had built with Ruby 2.7 and Rails 6.0 with Ruby 3 and Rails 6.1. I'm using the rails admin gem along with devise and cancancan. In my old project I've got no issues creating a simple EventCategory object. When I try now I get:

enter image description here

and:

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" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["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'

This is my model in 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

I would really appreciate some guidance with this one.

moyejg
  • 125
  • 8
  • I'd walk back to Rails 6.0 and see if the issue is with the Rails upgrade or the Ruby upgrade. In either case, ActiveAdmin has likely not be updated for one or the other. – dbugger Dec 28 '20 at 19:40
  • https://github.com/sferik/rails_admin/issues/3342#issuecomment-783460322 it was fixed on master but not yet released so at v2.0.2 you need to pull in the gem from master directly to get the fix – jethroo Feb 27 '21 at 20:17

1 Answers1

1

My guess is you may have been getting a deprecation warning in ruby 2.7 that now returns the error you're seeing in ruby 3.0. According the the ruby 3.0 changelist, if you want to pass a hash as an argument to a method that expects keyword arguments, you must use the double splat operator (**).

I'm not familiar with RailsAdmin (I normally use ActiveAdmin), but if you know of a way to "intercept" the params and pass them to the save method using the ** operator, it should resolve your problem.

  • 1
    Thank you this led me to a fix. Was missing ** before options on line 23 of abstract_object.rb in the rails_admin code. They already had it there but for some reason my code was missing it. Must have had an older version of the gem in there. Thanks again. – moyejg Dec 28 '20 at 22:37