class ModelName < ActiveRecord::Base
has_one :model_name_2
# real attributes a, b
attr_accessor :c, :d
delegate e, :to => :model_name_2
end
Now an instance (mn) of type ModelName calling to_xml will output
mn.to_xml
Now to override the to_xml to include attributes c, d and e.
class ModelName < ActiveRecord::Base
has_one :model_name_2
class ModelName < ActiveRecord::Base
has_one :model_name_2
# real attributes a, b
attr_accessor :c, :d
delegate e, :to => :model_name_2
def to_xml
super(:methods => [:c, :d, e])
end
end
Now when to_xml is called on the model c, d and e will also be included.
mn.to_xml
more to_xml goodness at http://apidock.com/rails/ActiveRecord/Serialization/to_xml
No comments:
Post a Comment