Class: ActiveRecord::Errors
- Inherits:
-
Object
- Object
- ActiveRecord::Errors
- Defined in:
- lib/restfulx/rx_active_record.rb
Overview
Add more extensive reporting on errors including field name along with a message when errors are serialized to XML and JSON
Instance Method Summary collapse
-
#to_amf(options = {}) ⇒ Object
serialize errors to AMF.
-
#to_fxml(options = {}) ⇒ Object
serializer errors to fXML.
-
#to_json(options = {}) ⇒ Object
serialize errors to JSON.
- #to_json_original ⇒ Object
Instance Method Details
#to_amf(options = {}) ⇒ Object
serialize errors to AMF
354 355 356 357 358 |
# File 'lib/restfulx/rx_active_record.rb', line 354 def to_amf( = {}) [:amf_version] = 3 [:serializer] ||= RestfulX::AMF::RxAMFSerializer.new [:serializer].serialize_errors(Hash[*@errors.to_a.flatten]).to_s end |
#to_fxml(options = {}) ⇒ Object
serializer errors to fXML
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/restfulx/rx_active_record.rb', line 330 def to_fxml( = {}) [:root] ||= "errors" [:indent] ||= 2 [:builder] ||= Builder::XmlMarkup.new(:indent => [:indent]) [:builder].instruct! unless .delete(:skip_instruct) [:builder].errors do |e| # The @errors instance variable is a Hash inside the Errors class @errors.each do |attr, msg| next if msg.nil? if attr == "base" [:builder].error("message", msg.to_s) else [:builder].error("field" => attr.camelcase(:lower), "message" => msg.to_s) end end end end |
#to_json(options = {}) ⇒ Object
serialize errors to JSON
349 350 351 |
# File 'lib/restfulx/rx_active_record.rb', line 349 def to_json( = {}) "{#{'errors'.inspect}:#{to_json_original()}}" end |
#to_json_original ⇒ Object
327 |
# File 'lib/restfulx/rx_active_record.rb', line 327 alias_method :to_json_original, :to_json |