# frozen_string_literal: true # Helpers module ApplicationHelper # Devuelve el atributo name de un campo posiblemente anidado def field_name_for_post(names) return ['post', names] if names.is_a? String names = names.dup root = 'post' name = names.pop names.each do |n| root = "#{root}[#{n}]" end [root, name] end def field_name_for_post_as_string(names) f = field_name_for_post(names) "#{f.first}[#{f.last}]" end def distance_of_time_in_words_if_more_than_a_minute(seconds) if seconds > 60 distance_of_time_in_words seconds else I18n.t('seconds', seconds: seconds) end end def sanitize_markdown(text, options = {}) sanitize(CommonMarker.render_html(text), options) end def invalid?(model, field) model.errors.messages[field].present? end def form_control(model, field) if invalid? model, field 'form-control is-invalid' else 'form-control' end end def form_class(model) model.errors.messages.empty? ? 'needs-validation' : 'was-validated' end end