Forum: Ruby on Rails serving xml

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Adrian C. (Guest)
on 2009-03-31 07:16
Hi All,

I'm trying to serve some XML from my Rails 2.0 server.

I have a Flash file that always reads its configuration from
/home/gallery.xml

So, I would like to build the contents from the database and serve it
back to the flash file when it hits my xml url.

If it was HTML that it was asking for then in my home controller I have
a gallery method that serves back a gallery.html.erb but since it wants
xml I figured that it would need a gallery.xml.erb and a method like
below in my home controller.

  def gallery

    @collection = Collection.find_by_name("banner")

    respond_to do |format|
      format.html # gallery.html.erb
      format.xml  { render :xml => @collection }
    end

  end


But, this gives me the routing error:
No route matches "/home/gallery.xml" with {:method=>:get}

So, I've tried renaming my gallery.xml.erb to gallery.xml.builder but
still no luck. I suspect that it's a problem with my understanding of
routing but the html version responds as expected through /home/gallery
but not /home/gallery.html.

Any help?

Cheers
bill walton (Guest)
on 2009-03-31 07:28
(Received via mailing list)
Hi Adrian,

On Tue, 2009-03-31 at 05:16 +0200, Adrian Cook wrote:

> But, this gives me the routing error:
> No route matches "/home/gallery.xml" with {:method=>:get}

What's your routes.rb look like?

Bill
Adrian C. (Guest)
on 2009-03-31 07:35
Hi Bill,

bill walton wrote:
>
> What's your routes.rb look like?
>
> Bill

Here it is:
ActionController::Routing::Routes.draw do |map|
  map.resources :gifts

  map.resources :mailing_list_users

  map.resources :downloads

  map.resources :multi_currency_prices

  map.resources :billing_infos

  map.simple_captcha '/simple_captcha/:action', :controller =>
'simple_captcha'

  map.resources :download_locations

  map.resources :drm_types

  map.resources :pages

  map.resources :products

  map.with_options :controller => 'products' do |products|
    map.resources :buy
  end


  map.resources :reviews

  map.resources :collections

  map.namespace(:admin) do |admin|

    admin.resources :clients, :collection => {  :multi_report => :put,
                                                :multi_report_generate
=> :put }

    admin.resources :user_groups

    admin.resources :discounts

    admin.resources :collections

    admin.resources :reviews

    admin.resources :order_items

    admin.resources :coupon_types

    admin.resources :product_types

    admin.resources :clients

    admin.resources :platforms

    admin.resources :products

    admin.resources :coupons

    admin.resources :countries

    admin.resources :payments

    admin.resources :orders

    admin.resources :payment_types

    admin.resources :portal_users

    admin.resources :billing_infos

    admin.resources :exchange_rates

    admin.resources :download_locations

    admin.resources :drm_types

    admin.resources :downloads

    admin.resources :article_headers

    admin.resources :articles

    admin.resources :mailing_list_users

    admin.resources :mailing_list_bulletins

    admin.resources :mailing_list_groups

    admin.resources :pages

  end

  map.root :controller => "home"

  # Install the default routes as the lowest priority.
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end
bill walton (Guest)
on 2009-03-31 08:13
(Received via mailing list)
Hi Adrian,

On Tue, 2009-03-31 at 05:35 +0200, Adrian Cook wrote:
> Hi Bill,
>
> bill walton wrote:
> >
> > What's your routes.rb look like?
> >
> > Bill
>
> Here it is:
<snip>
>   map.connect ':controller/:action/:id.:format'

Thanks.  Just wanted to verify you hadn't somehow clobbered the last
route.

Take a look at the Accept header of the incoming request (Live HTTP
Headers if you don't already have a different preferred tool).  My guess
is you're not getting a request for xml.  Post back if that's not it.

Best regards,
Bill
This topic is locked and can not be replied to.