• 30apr

    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

    Tags: ,

   

Recent Comments

  • It's very strange, you're right... The code seems to be ok....
  • it is using its default renderer.. ...
  • I'm sorry but I cannot understand. If you have commented out...
  • hi, am also having this ghost image problem.. problem is tha...
  • Ok, I think I could elaborate on that =) Take this method: ...