In below example, the middle_name
is optional. Any name without middle_name
it takes an extra blank space. Please anyone make correction following method.
def name
"#{first_name} #{middle_name} #{last_name}".titleize
end
You can try this:
def name
[first_name, middle_name, last_name].select(&:present?).join(' ').titleize
end
Use this instead
def name
[first_name, middle_name, last_name].reject(&:blank?).join(' ').titleize
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With