-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
error_notification.rb
48 lines (39 loc) · 1.1 KB
/
error_notification.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module SimpleForm
class ErrorNotification
delegate :object, :object_name, :template, to: :@builder
def initialize(builder, options)
@builder = builder
@message = options.delete(:message)
@options = options
end
def render
if has_errors?
template.content_tag(error_notification_tag, error_message, html_options)
end
end
protected
def errors
object.errors
end
def has_errors?
object && object.respond_to?(:errors) && errors.present?
end
def error_message
(@message || translate_error_notification).html_safe
end
def error_notification_tag
SimpleForm.error_notification_tag
end
def html_options
@options[:class] = "#{SimpleForm.error_notification_class} #{@options[:class]}".strip
@options
end
def translate_error_notification
lookups = []
lookups << :"#{object_name}"
lookups << :default_message
lookups << "Please review the problems below:"
I18n.t(lookups.shift, scope: :"simple_form.error_notification", default: lookups)
end
end
end