arvias
November 10, 2008, 4:16pm
1
Hi,
I have an array with objects and I want to generate an XML like:
1
result 1
2
result 2
The helper method generates some urls and it needs as an arguments the
object.
What would be a proper way to include the result of that method call?
I guess building the xml manually could work, but that means I would
have to manually enter every object variable.
–
M.
arvias
November 11, 2008, 8:51pm
2
modify the to_xml method of your object, like so:
class MyObject < ActiveRecord::Base
def helper_method(obj)
“something-from-obj-#{obj.id}”
end
def to_xml
xml = super
close_tag = “</#{self.class.to_s.underscore.dasherize}>”
xml.gsub(close_tag, " #{self.helper_method(self)}\n#{close_tag}")
end
end
arvias
November 12, 2008, 3:02pm
3
My problem is that the helper method, is a Helper(app/helpers)
Method.
And I can’t use it in the model. Otherwise I could have called to_xml
( :method => etc).
–
M.
arvias
November 12, 2008, 3:14pm
4
In your model, you should just be able to include the helper:
class MyObject < ActiveRecord::Base
include SomeHelper
end