This would be cleaner:

    user.user_credentials.where(:credential_name => name).first.try(:credential_value) || nil