Sha256: 2198d61c291672007c322ea0a76af8416663d5e9b68537c2689c704e8fbc3b13

Contents?: true

Size: 1.19 KB

Versions: 29

Compression:

Stored size: 1.19 KB

Contents

module Renalware
  module FormHelper
    def errors_css_class(model, attr)
      " field_with_errors" if model.errors.key?(attr)
    end

    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

    def input_partial_path_for(renderable)
      partial_type = partial_type_for(renderable)
      "renalware/shared/documents/#{partial_type}_input"
    end

    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

    def monospace(value, width = 5)
      content_tag(:span, class: "monospaced") do
        concat("%#{width}s" % value).gsub(/ /, " ").html_safe
      end
    end

    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
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
renalware-core-2.0.16 app/helpers/renalware/form_helper.rb
renalware-core-2.0.15 app/helpers/renalware/form_helper.rb
renalware-core-2.0.14 app/helpers/renalware/form_helper.rb
renalware-core-2.0.13 app/helpers/renalware/form_helper.rb
renalware-core-2.0.12 app/helpers/renalware/form_helper.rb
renalware-core-2.0.11 app/helpers/renalware/form_helper.rb
renalware-core-2.0.9 app/helpers/renalware/form_helper.rb
renalware-core-2.0.8 app/helpers/renalware/form_helper.rb
renalware-core-2.0.7 app/helpers/renalware/form_helper.rb
renalware-core-2.0.5 app/helpers/renalware/form_helper.rb
renalware-core-2.0.4 app/helpers/renalware/form_helper.rb
renalware-core-2.0.3 app/helpers/renalware/form_helper.rb
renalware-core-2.0.2 app/helpers/renalware/form_helper.rb
renalware-core-2.0.1 app/helpers/renalware/form_helper.rb
renalware-core-2.0.0 app/helpers/renalware/form_helper.rb
renalware-core-2.0.0.pre.rc13 app/helpers/renalware/form_helper.rb
renalware-core-2.0.0.pre.rc11 app/helpers/renalware/form_helper.rb
renalware-core-2.0.0.pre.rc10 app/helpers/renalware/form_helper.rb
renalware-core-2.0.0.pre.rc9 app/helpers/renalware/form_helper.rb
renalware-core-2.0.0.pre.rc8 app/helpers/renalware/form_helper.rb