<% # name: headmin/forms/image # # ==== Options # * form - Form object # * attribute - Name of the attribute of the form model # * label - Text to show as label. Label will be hidden if value is false # # ==== Examples # Basic version # <%= render 'headmin/forms/image', form: form, attribute: :image %#> class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false data = local_assigns.has_key?(:data) ? data : nil disabled = local_assigns.has_key?(:disabled) ? disabled : false label = local_assigns.has_key?(:label) ? label : nil readonly = local_assigns.has_key?(:readonly) ? readonly : false required = local_assigns.has_key?(:required) ? required : false has_image = form.object.send(attribute).attached? options = { 'aria-describedby': form_field_validation_id(form, attribute), class: "form-control #{form_field_validation_class(form, attribute)} #{class_names}", data: data, disabled: disabled, placeholder: attribute, readonly: readonly, required: has_image ? false : required, } show_label = label != false %>
<% if show_label %> <%= render 'headmin/forms/label', form: form, attribute: attribute, name: label, required: required %> <% end %>
<% if has_image %> <%= image_tag(form.object.send(attribute).variant(resize_to_limit: [200, 200], quality: 70), class: 'img-thumbnail') %> <% else %> A generic square placeholder image with a white border around it, making it resemble a photograph taken with an old instant camera 200x200 <% end %>
<%= form.file_field(attribute, options) %> <%= render 'headmin/forms/validation', form: form, attribute: attribute %>