Class: ActiveModel::Errors
- Inherits:
-
Object
- Object
- ActiveModel::Errors
- Defined in:
- lib/couch_i18n/active_model_errors.rb
Instance Method Summary collapse
- #full_message(attribute, message) ⇒ Object
- #full_messages ⇒ Object
-
#generate_message(attribute, type = :invalid, options = {}) ⇒ Object
The code for this method is base on rails revision: f3531a8fc9f661f96759f0a851540745876e5d6c The error lookup now consists of: namespace.errors.messages.
Instance Method Details
#full_message(attribute, message) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/couch_i18n/active_model_errors.rb', line 30 def (attribute, ) return if attribute == :base attr_name = attribute.to_s.gsub('.', '_').humanize attr_name = @base.class.human_attribute_name(attribute, :default => attr_name) # Create key. Remove class in model name and add errors.messages key = (@base.class.model_name.underscore.sub(/\w+$/, '').scan(/\w+/) + ['errors.conjunction.attribute_message']).join('.') I18n.t(key, { :default => "%{attribute} %{message}", :attribute => attr_name, :message => }) end |
#full_messages ⇒ Object
26 27 28 |
# File 'lib/couch_i18n/active_model_errors.rb', line 26 def map { |attribute, | (attribute, ) } end |
#generate_message(attribute, type = :invalid, options = {}) ⇒ Object
The code for this method is base on rails revision: f3531a8fc9f661f96759f0a851540745876e5d6c The error lookup now consists of: namespace.errors.messages
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/couch_i18n/active_model_errors.rb', line 9 def (attribute, type = :invalid, = {}) type = .delete(:message) if [:message].is_a?(Symbol) value = (attribute != :base ? @base.send(:read_attribute_for_validation, attribute) : nil) # Create key. Remove class in model name and add errors.messages key = (@base.class.model_name.underscore.sub(/\w+$/, '').scan(/\w+/) + ['errors.messages', type]).join('.') = { :model => @base.class.model_name.human, :attribute => @base.class.human_attribute_name(attribute), :value => value }.merge() I18n.translate(key, ) end |