Skip to content

Commit

Permalink
Merge pull request #1394 from namusyaka/remove-code-duplication
Browse files Browse the repository at this point in the history
Remove code duplication in error_messages_for.
  • Loading branch information
ujifgc committed Sep 4, 2013
2 parents 920e45b + 0bd1072 commit 2a263cc
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions padrino-helpers/lib/padrino-helpers/form_helpers.rb
Expand Up @@ -194,19 +194,19 @@ def error_messages_for(*objects)
end
end

options[:object_name] ||= objects.first.class
options[:object_name] ||= objects.first.class.to_s.underscore.gsub(/\//, ' ')

I18n.with_options :locale => options[:locale], :scope => [:models, :errors, :template] do |locale|
header_message = if options.include?(:header_message)
options[:header_message]
else
object_name = options[:object_name].to_s.underscore.gsub(/\//, ' ')
object_name = options[:object_name]
object_name = I18n.t(:name, :default => object_name.humanize, :scope => [:models, object_name], :count => 1)
locale.t :header, :count => count, :model => object_name
end
message = options.include?(:message) ? options[:message] : locale.t(:body)
error_messages = objects.map { |object|
object_name = options[:object_name].to_s.underscore.gsub(/\//, ' ')
object_name = options[:object_name]
object.errors.map { |f, msg|
field = I18n.t(f, :default => f.to_s.humanize, :scope => [:models, object_name, :attributes])
content_tag(:li, "%s %s" % [field, msg])
Expand Down

0 comments on commit 2a263cc

Please sign in to comment.