Since all my efforts to control how to_xml() is formatting dates has
failed, I'm now considering writing my own to_xml().  However, from
the limited examples I've found, I just don't understand how to
actually reference the columns for the records in my record set.

Here's a simplified view of my ActiveRecord object:

class Errors < ActiveRecord::Base
  set_table_name "legacy_errors"

  # legacy_errors has three columns: id, msg, error_date
  # Since the default to_xml is generating error_dates in the format
"Mon Nov 03 00:00:00 -0600 2008",
  #    and I cannot seem to force a different behavior, I want to
create my own to_xml.

  # Examples online show the following as how to override to_xml:
    def to_xml(options = {})
      options[:indent] ||= 2
      xml = options[:builder] ||= Builder::XmlMarkup.new(:indent =>
options[:indent])
      xml.instruct! unless options[:skip_instruct]
      # v v v
      xml.level_one do
        xml.tag!(:second_level, 'content')
      end
      # ^ ^ ^
    end
end

The code between the v and ^ markers is where the body of each XML
object is generated.  If I were generating by hand, I would do
something like this:
errors.each do |err|
  s << "<id>" << err.id << "</id>"
  s << "<msg>" << err.msg << "</msg>"
  s << "<error_date>" << err.error_date.strftime("%Y-%m-%d") << "</
error_date>"
end

I'm not at all understanding how to do my thing within the v ^ section
of to_xml().

Any help is appreciated!

Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to