ForestAdmin / forest-rails

💎 Ruby on Rails agent for Forest Admin to integrate directly to your existing Ruby on Rails backend application.
https://www.forestadmin.com
GNU General Public License v3.0
374 stars 77 forks source link

[*] Rails 6 - Record creation fails #314

Closed FraDim closed 5 years ago

FraDim commented 5 years ago

Expected behavior

When creating a resource with valid fields in Forest Admin Then the resource should be created and displayed

Actual behavior

When creating a resource with valid fields in Forest Admin Then I get a popup with the message

wrong number of arguments (given 2, expected 0..1)

And no resource has been created

Failure Logs

Where InventoryLevel is the resource that I tried to create (snipped for clarity):

Started POST "/forest/InventoryLevel" for 127.0.0.1 at 2019-05-13 12:57:50 +0100
Processing by ForestLiana::UserSpace::InventoryLevelController#create as JSON
  Parameters: 
        {
          "data" => {
            "attributes" => {
              "quantity_available" => 2
            },
            "type" => "InventoryLevels"
          },
          "collection" => "InventoryLevel"
        }

Completed 400 Bad Request in 306ms (Views: 0.6ms | ActiveRecord: 3.2ms | Allocations: 140946)

Context

Debugging

The method ResourceCreator#has_strong_parameter checks for the arity of ActiveRecord::Persistence#update_attributes! in order to decide whether to create the record with the option without_protection or not.

The problem arises because the update_attributes! method is deprecated in Rails 6 and is now an alias of the update! method (in the past it has been the opposite) and the arity check returns an unexpected value:

ActiveRecord::Base.instance_method(:update!).arity # => 1
ActiveRecord::Base.instance_method(:update_attributes!).arity # => -1

This causes the option without_protection: true to be passed to the create method of ActiveRecord, which is not accepted.

arnaudbesnier commented 5 years ago

Hi @FraDim It should be fixed with the liana v4.1.0.

Feel free to reopen this ticket if the issue persists.