Producing custom xml from index action
Upon trying to pull up the following u开发者_如何学JAVArl:
{base}/log_items.xml
I wanted to produce something like:
<log>
<event class="x" time="y">z</event>
<event class="x" time="y">z</event>
...
</log>
I have the following in my index action
def index
@log_items = LogItem.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @log_items }
end
end
...and I overrode the to_xml method in the log_item.rb model file
def to_xml(options = {})
xml = Builder::XmlMarkup.new(:indent=>2)
xml.event (description, "class" => category, "time" => created_at)
end
This works when I pull up a log event individually, but fails to produce the enumeration of events through the index method. Any clue what I'm doing wrong?
精彩评论