small medium large xlarge

Generic-user-small
04 Mar 2008, 20:06
Tony Bianco (2 posts)

I’m on one of the last chapters of AWDWR using 2.0 and I’m at the part where I should be showing xml. The problem is that it seems to not be parsing the xml.

Here’s my code

Controller

class InfoController < ApplicationController

  def who_bought
    respond_to do |format| 
      format.xml {
        @product = Product.find(params[:id])
        @orders = @product.orders
      }
    end
  end
end

View who_bought.xml.erb

xml.order_list(:for_product => @product.title) do
  for o in @orders
    xml.order do
      xml.name(o.name)
      xml.email(o.email)
    end
  end
end

When I go to a page I get this error in the browser and instead of showing xml it just shows what’s in the *.xml.erb file (example url http://localhost:3000/info/who_bought/48126371)

bq. XML Parsing Error: not well-formed Location: http://localhost:3000/info/who_bought/48126371 Line Number 1, Column 15: xml.order_list(:for_product => @product.title) do

What am I doing wrong here.

Generic-user-small
04 Mar 2008, 22:54
Tony Bianco (2 posts)

Here’s where I went wrong. I named my filed who_bought.xml.erb. What I should have done is named the file who_bought.xml.builder, as soon as I did that it worked!

You must be logged in to comment