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'