Skip to content
This repository has been archived by the owner on May 8, 2022. It is now read-only.

update gem for rails 6.1 + ruby 3.0.2 #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/action_view/helpers/dynamic_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def error_messages_for(*params)

message = options.include?(:message) ? options[:message] : locale.t(:body)

error_messages = objects.sum do |object|
error_messages = objects.map do |object|
object.errors.full_messages.map do |msg|
content_tag(:li, msg)
end
Expand Down
33 changes: 14 additions & 19 deletions lib/active_model/dynamic_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,22 @@ class Errors
def full_messages
full_messages = []

each do |attribute, messages|
messages = Array.wrap(messages)
next if messages.empty?

if attribute == :base
messages.each {|m| full_messages << m }
each do |error|
if error.attribute == :base
full_messages << error.message
else
attr_name = attribute.to_s.gsub('.', '_').humanize
attr_name = @base.class.human_attribute_name(attribute, :default => attr_name)
attr_name = error.attribute.to_s.gsub('.', '_').humanize
attr_name = @base.class.human_attribute_name(error.attribute, :default => attr_name)
options = { :default => "%{attribute} %{message}", :attribute => attr_name }

messages.each do |m|
if m =~ /^\^/
options[:default] = "%{message}"
full_messages << I18n.t(:"errors.dynamic_format", options.merge(:message => m[1..-1]))
elsif m.is_a? Proc
options[:default] = "%{message}"
full_messages << I18n.t(:"errors.dynamic_format", options.merge(:message => m.call(@base)))
else
full_messages << I18n.t(:"errors.format", options.merge(:message => m))
end
if error.message =~ /^\^/
options[:default] = "%{message}"
full_messages << I18n.t(:"errors.dynamic_format", **options.merge(:message => error.message[1..-1]))
elsif error.message.is_a? Proc
options[:default] = "%{message}"
full_messages << I18n.t(:"errors.dynamic_format", **options.merge(:message => error.message.call(@base)))
else
full_messages << I18n.t(:"errors.format", **options.merge(:message => error.message))
end
end
end
Expand All @@ -44,4 +39,4 @@ def full_messages
end

require 'active_support/i18n'
I18n.load_path << File.dirname(__FILE__) + '/locale/en.yml'
I18n.load_path << File.dirname(__FILE__) + '/locale/en.yml'