Module: PagesCore::Admin::LabelledFieldHelper

Included in:
AdminHelper
Defined in:
app/helpers/pages_core/admin/labelled_field_helper.rb

Instance Method Summary collapse

Instance Method Details

#image_upload_field(form, label, method = :image, options = {}) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/pages_core/admin/labelled_field_helper.rb', line 30

def image_upload_field(form, label, method = :image, options = {})
  output = ""
  if form.object.send(method)
    output += (:p,
                          dynamic_image_tag(form.object.send(method),
                                            size: "120x100"))
  end
  output + labelled_field(
    form.file_field(method),
    label, { errors: form.object.errors[method] }.merge(options)
  )
end

#labelled_field(field, label, options = {}) ⇒ Object

Generate HTML for a field, with label and optionally description and errors.

The options are:

  • :description: Description of the field

  • :errors: Error messages for the attribute

An example:

<%= form_for @user do |f| %>
  <%= labelled_field f.text_field(:username), "Username",
                     description: "Choose your username",
                     errors: @user.errors[:username] %>
  <%= submit_tag "Save" %>
<% end %>

19
20
21
22
23
24
25
26
27
28
# File 'app/helpers/pages_core/admin/labelled_field_helper.rb', line 19

def labelled_field(field, label, options = {})
  (:div, class: labelled_field_class(options)) do
    safe_join(
      [labelled_field_label(label, options),
       labelled_field_description(options[:description]),
       field,
       (options[:check_box_description] || "")]
    )
  end
end