<%- error_attr = attr.to_s.sub(/price_str$/, 'price_minor') error_attr = f.object.has_attribute?(error_attr) ? error_attr : attr -%> <%= f.text_field attr, class: f.object.errors.include?(error_attr) ? 'field_with_errors' : nil, title: f.object.errors.full_messages_for(error_attr).uniq.join("\n") %>