test/dummy/app/helpers/application_helper.rb in upgrow-0.0.2 vs test/dummy/app/helpers/application_helper.rb in upgrow-0.0.3
- old
+ new
@@ -22,11 +22,13 @@
result += label(method, class: 'label') if method && label
result += yield
if method
errors_for(method).each do |error|
- result += @template.content_tag(:p, error, class: 'help is-danger')
+ result += @template.content_tag(
+ :p, error.message, class: 'help is-danger'
+ )
end
end
result
end
@@ -44,10 +46,11 @@
#
# @return [String] an HTML safe markup content.
def text_field(method, label: true, expanded: false, field: true, **args)
input_class = ['input']
input_class << 'is-danger' if errors_for(method).any?
+
output = control(expanded: expanded) do
super(method, class: input_class, **args)
end
if field
@@ -66,10 +69,32 @@
end
field(method: method, label: true) { output }
end
+ def email_field(method, **args)
+ input_class = ['input']
+ input_class << 'is-danger' if errors_for(method).any?
+
+ output = control(expanded: false) do
+ super(method, class: input_class, **args)
+ end
+
+ field(method: method, label: true) { output }
+ end
+
+ def password_field(method, **args)
+ input_class = ['input']
+ input_class << 'is-danger' if errors_for(method).any?
+
+ output = control(expanded: false) do
+ super(method, class: input_class, **args)
+ end
+
+ field(method: method, label: true) { output }
+ end
+
# Render a form submit button.
#
# @param text [Symbol] the text for the button.
# @param field [Boolean] if the button is within a field.
# @param data [Hash] the HTML data attribute.
@@ -93,10 +118,9 @@
yield
end
end
def errors_for(method)
- (options[:errors] || ActiveModel::Errors.new(self))
- .full_messages_for(method)
+ (options[:errors] || []).select { |error| error.attribute == method }
end
end
end