Here is Prob. 21, Exercises 8.9, in the book Calculus volume II by Tom M. Apostol, 2nd edition:
A set $S$ in $\mathbb{R}^n$ is called convex if for every pair of points $\mathbf{a}$ and $\mathbf{a}$ in $S$ the line segment from $\mathbf{a}$ to $\mathbf{b}$ is also in $S$; in other words, $t \mathbf{a} + (1-t) \mathbf{b} \in S$ for each $t$ in the interval $0 \leq t \leq 1$.
(a) Prove that every $n$-ball is convex.
(b) If $f^\prime ( \mathbf{x}; \mathbf{y} ) = 0$ for every $\mathbf{x}$ in an open convex set $S$ and for every $\mathbf{y}$ in $\mathbb{R}^n$, prove that $f$ is constant on $S$.
Part (a)
Let $\mathbf{p}$ be a given point in $\mathbb{R}^n$, and let $\delta$ be a given positive real number. Then the $n$-ball $B( \mathbf{p} ; \delta )$ is given by $$ B( \mathbf{p} ; \delta ) \colon= \{ \ \mathbf{x} \in \mathbb{R}^n \ \colon \ \lVert \mathbf{x} - \mathbf{p} \rVert < \delta \ \}, $$ where $$ \lVert \mathbf{y} \rVert = \sqrt{ \sum_{i=1}^n \left\lvert y_i \right\rvert^2 } $$ for any point $$ \mathbf{y} \colon= \left( y_1, \ldots, y_n \right) $$ in $\mathbb{R}^n$.
Suppose $\mathbb{a}$ and $\mathbb{b}$ are any two points in $B( \mathbf{p} ; \delta )$ and suppose that $t$ is any real number such that $0 \leq t \leq 1$. Then $\mathbb{a}$ and $\mathbb{b}$ are in $\mathbb{R}^n$, and we also have $$ \lVert \mathbf{a} - \mathbf{p} \rVert < \delta, \qquad \mbox{ and } \qquad \lVert \mathbf{b} - \mathbf{p} \rVert < \delta. $$ So $$ \begin{align} \lVert t \mathbf{a} + (1-t) \mathbf{b} - \mathbf{p} \rVert &= \lVert t \mathbf{a} + (1-t) \mathbf{b} - [t + (1-t)] \mathbf{p} \rVert \\ &= \lVert t ( \mathbf{a} - \mathbf{p} ) + (1-t) ( \mathbf{b} - \mathbf{p} ) \rVert \\ &\leq \lVert t ( \mathbf{a} - \mathbf{p} ) \rVert + \lVert (1-t) ( \mathbf{b} - \mathbf{p} ) \rVert \\ &= \lvert t \rvert \lVert \mathbf{a} - \mathbf{p} \rVert + \lvert 1-t \rvert \lVert \mathbf{b} - \mathbf{p} \rVert \\ &= t \lVert \mathbf{a} - \mathbf{p} \rVert + ( 1-t ) \lVert \mathbf{b} - \mathbf{p} \rVert \ [ \mbox{ because } \ t \in [0, 1] \ \mbox{ and } \ 1-t \in [0, 1] \ ] \\ &< t \delta + (1-t) \delta \\ &= \delta, \end{align} $$ which shows that the point $t \mathbf{a} + (1-t) \mathbf{b}$ is also in $B( \mathbf{p}; \delta )$. Hence $B( \mathbf{p}; \delta )$ is convex.
Part (b)
Suppose that $S$ is an open convex set in $\mathbb{R}^n$, suppose that $f^\prime( \mathbf{x}; \mathbf{y} ) = 0$ for every $\mathbf{x} \in S$ and for every $\mathbf{y} \in \mathbb{R}^n$, and suppose that $\mathbf{a}$ and $\mathbf{b}$ are any two points in $S$. Then, for every $t \in [0, 1]$, the point $t \mathbf{a} + (1-t) \mathbf{b}$ is also in $S$. Now if we put $$ \mathbf{y} \colon= \mathbf{b} - \mathbf{a}, $$ then, by the mean-value theorem for scalar fields, we can conclude that, for some real number $\theta \in (0, 1)$, we have $$ f( \mathbf{b} ) - f( \mathbf{a} ) = f( \mathbf{a} + \mathbf{y} ) - f( \mathbf{a} ) = f^\prime ( \mathbf{a} + \theta \mathbf{y} ; \mathbf{y} ). \tag{1} $$ Now $$ \mathbf{a} + \theta \mathbf{y} = \mathbf{a} + \theta (\mathbf{b} - \mathbf{a} ) = \theta \mathbf{b} + (1- \theta) \mathbf{a} \in S, $$ and thus $$ f^\prime ( \mathbf{a} + \theta \mathbf{y} ; \mathbf{y} ) = 0, $$ by our hypothesis. Therefore (1) gives $$ f( \mathbf{b} ) = f( \mathbf{a} ) $$ for any two points $\mathbf{a}$ and $\mathbf{b}$ in $S$. Hence $f$ is constant on set $S$.
Is this proof correct? If so, then do we really need our set $S$ to be open in $\mathbb{R}^n$? If not, then where is it that I'm going wrong?