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) ⇒ 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
18 19 20 21 |
# File 'app/helpers/renalware/form_helper.rb', line 18 def input_partial_path_for(renderable) partial_type = partial_type_for(renderable) "renalware/shared/documents/#{partial_type}_input" end |
#monospace(value, width = 5) ⇒ Object
31 32 33 34 35 |
# File 'app/helpers/renalware/form_helper.rb', line 31 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
23 24 25 26 27 28 29 |
# File 'app/helpers/renalware/form_helper.rb', line 23 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) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'app/helpers/renalware/form_helper.rb', line 9 def render_input(builder, attribute) renderable = builder.object.public_send(attribute) return unless renderable render input_partial_path_for(renderable), attribute: attribute, f: builder end |
#save_or_cancel(form:, back_path:, submit_title: "Save", cancel_title: "cancel") ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/helpers/renalware/form_helper.rb', line 37 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 |