开发者

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜