You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: beehives_controller.rb
    path of file: ./repos/ekylibre/app/controllers/backend
    
    the code of the file until where you have to start completion: # == License
# Ekylibre - Simple agricultural ERP
# 
    
    def update
      params = permitted_params.to_h
      params['boxes'] ||= []
      boxes = params['boxes'].to_h.sort_by { |a| a[0] }.map do |box|
        next unless box.second['cells']

        cells = box.second['cells'].symbolize_keys.sort_by { |a| a[0] }.map do |cell|
          cell.second.symbolize_keys
        end.compact
        cells.any? ? { cells: cells } : nil
      end.compact
      begin
        current_user.reload
        current_user.prefer!("beehive.#{params[:id]}", {
          version: Backend::BeehiveHelper::FORMAT_VERSION,
          boxes: boxes
        }.deep_stringify_keys.to_yaml)
        head :ok
      rescue ActiveRecord::StaleObjectError
        head :locked
      end
    end

    def reset
      if preference = current_user.preferences.find_by(name: "beehive.#{params[:id]}")
        preference.destroy!
      end
      head :ok
    end