When we say that something is 'just the ticket', we mean that it is ‘just right’ or ‘the correct thing to do’. The expression originally comes from ‘that’s the etiquette’. Etiquette, in turn, comes from French and Spanish words ('etiquette’ and ‘etiqueta’ respectively) and used to refer to a book of court ceremonies – a card which was given to those attending Court and contained directions and rules for correct behaviour. Therefore, etiquette nowadays refers to how to behave in polite society.
Example: 'If you love bright clothes, this neck-tie is just the ticket.'