In addition to using more concise syntax:
country.state.name unless country.state.nil?
I do not think there is a DRY way to do this with the information provided. I would say that if you cannot be sure that country.state is nothing or not, you can look at the code responsible for setting this value and determine whether this normal register should check if it should be.
source
share