Module: Renalware::FormHelper
- Defined in:
- app/helpers/renalware/form_helper.rb
Instance Method Summary collapse
- #errors_css_class(model, attr) ⇒ Object
- #input_partial_path_for(renderable) ⇒ Object
- #monospace(value, width = 5) ⇒ Object
- #partial_type_for(renderable) ⇒ Object
- #render_input(builder, attribute, html_options: {}) ⇒ Object
- #save_or_cancel(form:, back_path:, submit_title: "Save", cancel_title: "cancel") ⇒ Object
Instance Method Details
#errors_css_class(model, attr) ⇒ Object
5 6 7 |
# File 'app/helpers/renalware/form_helper.rb', line 5 def errors_css_class(model, attr) " field_with_errors" if model.errors.key?(attr) end |
#input_partial_path_for(renderable) ⇒ Object
19 20 21 22 |
# File 'app/helpers/renalware/form_helper.rb', line 19 def input_partial_path_for(renderable) partial_type = partial_type_for(renderable) "renalware/shared/documents/#{partial_type}_input" end |
#monospace(value, width = 5) ⇒ Object
32 33 34 35 36 |
# File 'app/helpers/renalware/form_helper.rb', line 32 def monospace(value, width = 5) content_tag(:span, class: "monospaced") do concat("%#{width}s" % value).gsub(/ /, " ").html_safe end end |
#partial_type_for(renderable) ⇒ Object
24 25 26 27 28 29 30 |
# File 'app/helpers/renalware/form_helper.rb', line 24 def partial_type_for(renderable) if renderable.respond_to?(:to_partial_path) renderable.to_partial_path.split("/").last else renderable.class.name.demodulize.underscore end end |
#render_input(builder, attribute, html_options: {}) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'app/helpers/renalware/form_helper.rb', line 9 def render_input(builder, attribute, html_options: {}) renderable = builder.object.public_send(attribute) return unless renderable render input_partial_path_for(renderable), attribute: attribute, f: builder, html_options: end |
#save_or_cancel(form:, back_path:, submit_title: "Save", cancel_title: "cancel") ⇒ Object
38 39 40 41 42 43 44 |
# File 'app/helpers/renalware/form_helper.rb', line 38 def save_or_cancel(form:, back_path:, submit_title: "Save", cancel_title: "cancel") capture do concat(form.submit(submit_title, class: "button")) concat(content_tag(:span) { " or " }) concat(link_to(cancel_title, back_path)) end end |