Module: PagesCore::Admin::LabelledFieldHelper
- Included in:
- AdminHelper
- Defined in:
- app/helpers/pages_core/admin/labelled_field_helper.rb
Instance Method Summary collapse
- #image_upload_field(form, label, method = :image, options = {}) ⇒ Object
-
#labelled_field(field, label, options = {}) ⇒ Object
Generate HTML for a field, with label and optionally description and errors.
Instance Method Details
#image_upload_field(form, label, method = :image, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/pages_core/admin/labelled_field_helper.rb', line 32 def image_upload_field(form, label, method = :image, = {}) output = "" if form.object.send(method) output += tag.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() ) 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 %>
21 22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/pages_core/admin/labelled_field_helper.rb', line 21 def labelled_field(field, label, = {}) tag.div(class: labelled_field_class()) do safe_join( [labelled_field_label(label, ), labelled_field_description([:description]), field, [:check_box_description] || ""] ) end end |