Class: RUI::Forms::Errors

Inherits:
Base
  • Object
show all
Includes:
Phlex::Rails::Helpers::Pluralize
Defined in:
lib/rui/forms/errors.rb

Instance Method Summary collapse

Constructor Details

#initialize(errors, object_name = "record") ⇒ Errors

Returns a new instance of Errors.



4
5
6
7
# File 'lib/rui/forms/errors.rb', line 4

def initialize(errors, object_name = "record")
  @errors = errors
  @object_name = object_name
end

Instance Method Details

#view_templateObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rui/forms/errors.rb', line 9

def view_template
  if @errors.any?
    div(class: "bg-red-50 text-red-500 p-10 font-medium rounded-md mt-3") do
      h2 { pluralize(@errors.count, "error") + " prohibited this #{@object_name} from being saved:" }
      ul(class: "list-disc ml-6") do
        @errors.each do |error|
          li { error.full_message }
        end
      end
    end
  end
end