Override rails model route

I’m trying to overriding the update method on a model’s controller. However, I’m unable to return a successful response from the overridden update method. I’ve posted my code below. Forest receives returns an error on success. What should a successful response look like? I’d like it to behave the same as it does without it being overridden. Thanks for your help

Code

module Forest
  class AddressResourcesController < ForestLiana::ResourcesController
    def update
      address = @resource.find(params[:id])
      address.assign_attributes(permitted_params)

      # Do other other things here

      if !address.valid?
        render status: 400, plain: "Address is invalid"
      else
        address.save!

        # what do I return?
      end
    end

    private

    def permitted_params
      return {} if params.dig(:data, :attributes).empty?

      params.require(:data).require(:attributes).permit()
    end
  end
end

config/routes.rb

put '/Address/:id', to: 'address_resources#update', collection: 'Address'

I’m answering my own post because someone from Forest helped me outside this forum and wanted to share the answers for others.

The render_record_jsonapi should be used to return a succesful response

Here’s the answer to the code above.

  #what do I return?
  render serializer: nil, json: render_record_jsonapi(address)
2 Likes

It looks like I spoke too soon.

I’m running into an issue where the an associated model fails be be included

ForestAdmin::JSONAPI::Serializer::InvalidIncludeError: 'user' is not a valid include.

  0) Forest::AddressResourcesController#update updates the address
     Failure/Error: render serializer: nil, json: render_record_jsonapi(address)

     ForestAdmin::JSONAPI::Serializer::InvalidIncludeError:
       'user' is not a valid include.

Hello @Logan_Keenan, and welcome to our community :wave:

I tested on my end but I can’t reproduce the error.
As Forest admin uses the json api format to handle relationships, you need to authorise the relationships key parameter in your controller.

Could you share your controller to help you :pray: