Method: ActiveResource::Errors#from_array
- Defined in:
- lib/active_resource/validations.rb
#from_array(messages, save_cache = false) ⇒ Object
Grabs errors from an array of messages (like ActiveRecord::Validations). The second parameter directs the errors cache to be cleared (default) or not (by passing true).
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/active_resource/validations.rb', line 16 def from_array(, save_cache = false) clear unless save_cache humanized_attributes = Hash[@base.known_attributes.map { |attr_name| [ attr_name.humanize, attr_name ] }] .each do || = humanized_attributes.keys.sort_by { |a| -a.length }.detect do |attr_name| if [0, attr_name.size + 1] == "#{attr_name} " add humanized_attributes[attr_name], [(attr_name.size + 1)..-1] end end add(:base, ) if .nil? end end |