• If you create a scaffold for your rails project, it will create for you a lot of things; for example, a way to show your object in xml format. But what about adding custom elements to that xml?

    I solved in this way:

    class MyObject < ActiveRecord::Base
      #[...]
      def to_xml(options={})
        cp = attributes.clone
        cp["something"] = "some value"
        cp["another thing"] = self.some_relation.length
        cp.to_xml(options)
      end
    end

    Posted by Armisael @ 08:54

    Tags: ,

Leave a Reply

Your email address will not be published.


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">