Skip to content

Instantly share code, notes, and snippets.

@lastcanal
Created April 6, 2013 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lastcanal/5326707 to your computer and use it in GitHub Desktop.
Save lastcanal/5326707 to your computer and use it in GitHub Desktop.
Adds Ohm model errors to padrino admin locales.
require 'yaml'
$mapping = {
format: :invalid,
not_present: :blank,
not_numeric: :not_a_number,
not_url: :invalid,
not_email: :invalid,
not_valid: :inclusion,
not_in_range: :inclusion,
not_decimal: :invalid
}
Dir.glob('*.yml').each do |filename|
yaml = YAML.load_file(filename)
ar_messages = yaml[yaml.keys.first]["activemodel"]["errors"]["messages"]
messages = $mapping.inject({}) do |messages, (ohm, ar)|
messages[ohm] = ar_messages[ar.to_s]
messages
end
File.open(filename, 'a') do |file|
file.puts <<-YAML
ohm:
errors:
messages:
YAML
indent = ' ' * 8
messages.each_pair do |key, value|
file.puts indent + "#{key}: \"#{value}\""
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment